To instruct an object to follow a sequence of waypoints, follow these steps:
- Replace the contents of the ArrowNPCMovement C# script class with the following:
using UnityEngine;
using UnityEngine.AI;
public class ArrowNPCMovement : MonoBehaviour {
private GameObject targetGo = null;
private WaypointManager waypointManager;
private NavMeshAgent navMeshAgent;
void Start () {
navMeshAgent = GetComponent<NavMeshAgent>();
waypointManager = GetComponent<WaypointManager>();
HeadForNextWayPoint();
}
void Update () {
float closeToDestinaton = navMeshAgent.stoppingDistance * 2;
if (navMeshAgent.remainingDistance < closeToDestinaton) {
HeadForNextWayPoint ();
}
}
private void HeadForNextWayPoint () {
targetGo = waypointManager.NextWaypoint (targetGo);
navMeshAgent.SetDestination (targetGo.transform.position);
}
}
- Create a new 3D Capsule object named Capsule-waypoint-0 at (-12, 0, 8).
- Copy Capsule-waypoint-0, name the copy Capsule...