UnityCreating Coin Distraction Feature in Unity (Part 4: Make Guards Go Back to the Waypoints Path)
Guards check the distraction and go back to their path.
Objective: When guards reach the coin, make them wait some seconds and go back to their default path.
In part 3 we managed to make the guards move to the coin, but after that they just stay there the rest of the game. To add some realism we are going to make the guards wait some seconds and then go back to the waypoints path.
In the WayBeforeMove Coroutine I change the value of the isStopped property of the nav mesh agent to make sure the guard stops the movement and starts the movement again.
Then I declared a bool variable called _otherMovement, if this variable is true the guard stops following the waypoints path, check for the distance between its position and the new destination and if the distance is less than 1, we set the _otherMovement variable to false and start the coroutine WaitBeforeMove (the guard waits some seconds before go back to the waypoints path).
And that’s it!!! The guards just check the coin position for some seconds and they go back to their path.