我想制作一个简单的脚本,将 NavMesh 代理引导到各种航点。我是 Unity 的新手,所以我还不知道一些基本功能,而是输入伪代码。
using UnityEngine;
using UnityEngine.AI;
public class Path_left_blue : MonoBehaviour {
private Transform target;
private int wavepointindex = 0;
public NavMeshAgent agent;
void Start () {
target = Waypoints_blue_left.waypoints[0];
}
void Update () {
//Set destination to waypoint
Vector3 dir = target.position;
agent.setDestination(dir);
if (agent is within a close range/touching target waypoint)
//Remove object if at the last waypoint
if (wavepointindex == Waypoints_blue_left.waypoints.Length)
Destroy(gameObject);
wavepointindex++;
target = Waypoints_blue_left.waypoints[wavepointindex];
}
}