Create a coin distraction system in Unity Part 3

Daniel Kirwan
2 min readJun 30, 2021

Objective: Update the Guard animations when they’re moving towards the coin distraction

I hope you have read the previous two parts to the system and are following along nicely.

There are a couple of things extra that I need to be able to change the guard animations when they’re moving towards the coin position.

I am only doing 1 thing extra in the Player script which is updating a variable inside of the GuardAI script. This coin_pos is the guards new destination that they need to move towards. I could have just updated the animations here but I also need the guards to change animation again once they reach their target. So for me it is better to do this is the waypoint system.

In the player class I am updating the bool _coinToss in the GuardAI script to true, so that the else statement in the GuardAI script is now running. I am now checking that the distance is less than 4, I chose this distance as if it is any smaller then AI will be running into each other trying to get to the coin position.

That’s it for changing the guard animations moving towards to the coin position.

--

--