效果图

编辑器可见,Game视窗不可见,适用于空物体位置可视化
代码如下:
using UnityEngine; using System.Collections.Generic;public class MudflowPathGuide : MonoBehaviour {[Header("路径点设置")]public List<Transform> pathPoints = new List<Transform>();[Header("路径可视化")]public bool showPath = true;public Color pathColor = new Color(1f, 0.5f, 0f, 0.8f);public float gizmoSize = 0.5f;void OnDrawGizmos(){if (!showPath || pathPoints.Count < 2) return;// 绘制路径点Gizmos.color = Color.red;foreach (var point in pathPoints){if (point != null){Gizmos.DrawSphere(point.position, gizmoSize);}}// 绘制路径线Gizmos.color = pathColor;for (int i = 0; i < pathPoints.Count - 1; i++){if (pathPoints[i] != null && pathPoints[i + 1] != null){Gizmos.DrawLine(pathPoints[i].position, pathPoints[i + 1].position);}}}}
本次就记录一下。
