Having a separate WaypointManager C# script class to simply swap between Capsule-waypoint-0 and Capsule-waypoint-3 may have seemed to be a bit heavy duty and a case of over-engineering, but this was actually a very good move. An instance object of the WaypointManager script class has the job of returning the next waypoint. It is now very straightforward to add the more sophisticated approach of having an array of waypoints, without us having to change any code in the ArrowNPCMovement C# script class. We can choose a random waypoint to be the next destination; for example, see the Choosing destinations – finding the nearest (or a random) spawnpoint recipe in Chapter 14, Choosing and Controlling Positions. Or, we can have an array of waypoints and choose the next one in the sequence.
To improve our game so that it works with an array of waypoints to be followed in sequence, we need to do the following...