Objective: Tell an AI sentry at which waypoints it may rest for a bit before continuing on its path.
We’ll begin by defining our own data structure, or struct. This struct will be made-up of a waypoint’s Transform and a bool to determine if the sentry can idle at that waypoint. We’ll need include using System to assign the Serializable tag so we can see it in the inspector.
Within the guard AI script, we create a List of WayPointPairs.
When there are waypoints and the sentry is not idling, the current waypoint is our destination. If we’re close to our destination, we’ll check if this waypoint is one we should idle at. If so, we’ll call the Idle coroutine, which will make the guard wait for a few seconds. Whether we waited or not, we’ll continue on to the next waypoint on the list.
Here’s the behavior we want for our example guard:
And here’s how we set that up within the inspector: