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.
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.