在场景中放置路径点,放置在一个数组里,示例代码使用的是车辆,其他模型可以参考。
路径点加入以下代码:
function OnDrawGizmos () {
// make a new array of waypoints, then set it to all of the transforms in the current object
var waypoints = gameObject.GetComponentsInChildren( Transform );
// now loop through all of them and draw gizmos for each of them
for ( var waypoint : Transform in waypoints ) {
Gizmos.DrawSphere( waypoint.position, 1.0 );
}
}
车辆上加上:
if (waypoint[0] == null)
{
for (int i = 0; i < 53; i++)
{
waypoint[i] = GameObject.Find("point" + i);
}
}
if (waypoint[currentwaypoint] != null)
{
Vector3 relativeposition = transform.InverseTransformPoint