创建一个WayPoint脚本,并挂载到Waypoint对象上,然后双击打开waypoint脚本进行编辑:
using UnityEngine;
public class WayPoint : MonoBehaviour {
//定义一个Transform类型的数组
public Transform[] waypoints;
private void Start()
{
//设置数组的大小为当前物体的子物体个数
waypoints = new Transform[transform.childCount];
int i = 0;
//遍历子物体,并将值依次赋给waypoint数组的每个项
foreach (Transform t in transform)
{
waypoints[i++] = t;
}
}