Toggling Damage Animation

Linking the Damage state when our enemy gets hit

It is now time to link everything together, the Animation, the Hit collision and the Health depletion.

Toggling the Damage Animation:

In the Animator window we are going to make sure that the Hit animation is transitioned from the “Any State”. Then we are going to transition to the Idle Animation (later on we will make this transition go towards the Fight Animation).

Then in the Skeleton script where the Damage Method is being applied, we are going to toggle the animation trigger. Since the parent Enemy script already has access to the Animation component we can just call the handler straight from the skeleton script.

If we test this out right now, you will noticed that the Skeleton does play the damage animation when being collided with the sword, the skeleton doesn’t stop moving. This is because we have nothing to toggle the parent enemy movement script to pause.

Skeleton doesn’t stop moving even when hit.

In the parent Enemy Script, we are going to first create a protected bool that will be by default set to “false”. This will set the condition to pause the skeleton movement.

In the movement method we are going to create the if statement that will only allow movement when the bool is set to false. By proxy when the bool is set to true, the skeleton should stop moving in place.

Finally back to the skeleton script, we are going to toggle the bool and set it to true when it is being hit.

The end result is the skeleton pausing movement when being hit.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Simon Truong

Simon Truong

A Designer, an Illustrator and a massive tech geek aspiring to become a professional Unity Developer.