Create a coin distraction system in Unity Part 2
Objective: Move the guards towards the coin thrown
The initial part of the system I created instantiates a coin prefab in the spot where the player right-clicks on the screen. Now I need to get the guards to move to the coin position but how will I update the GuardAI script to let the guards know that they have a new destination to reach?
In the method I have for detecting the right-click I am now calling a new method shown above.
I am storing all of the gameobjects with the tag of “Guard1”, this means I can then use a foreach loop to get a component that I will need to update the GuardAI script. This happens with all the guards that are in the scene. I am now setting the guards destination to move towards their new destination. But the issue is that the Guards will now start to move to the new destination but in the next frame they will continue on with moving between the waypoints.
So now I will need a bool that I can update inside of the GuardAI that will only allow the guards to move in the waypoint system if it is false.
Now that I have a bool that I can update I need to update the waypoint system inside the guards.
That is it for this article on moving the guards to the coin toss position. Come back for the next article where I will need to update the Guard animations.