Disrupting the default waypoint with coin distraction
After three months, I’m back to jotting my progress with Unity. Last time, I’ve created a waypoint system for the security guards which gets disrupted if the player is in their sight. This time around, they will be distracted by following the location of a tossed coin.
In terms of coding, I used a delegate to easily communicate the message to the guards, SendGuardsToCoin:
From the guards, we can interrupt their waiting period or if they are going to on of their waypoints.
Notice above that I added a variable _waitBeforeMovingActive to check if the Coroutine is active. There is just some additional handling for a case where the guard has just one waypoint.
When guard reaches waypoint the Coroutine for waiting is assigned to a variable so we can stop it from other methods by calling its name:
Also, from the code above, the security guard will go back to waiting and moving to its original waypoints after it reaches this custom location.
Now, it’s implemented in my game:
Also, let me just add that it’s important to properly set the radius of the NavMeshAgent so that the guards do not get stuck when they are near each other.