How to do it...

To check which Animator state is currently active, follow these steps:

  1. Import the character to Unity.
  2. Create an Animator Controller for it or use an existing one.
  3. If you want your character to react to hits, follow the Using transitions from Any State to play hit reactions recipe.
  4. In this recipe, we are going to use the healing action as an example. Create a new script and call it Healing.cs. In this script's Update() function, first we check if player pressed the H key. Then we check if our character is playing in the proper Animator state and saved in the public stringhealingAllowedState variable. We also check if a healing action is not active because we don't want to stack healing actions. If all these conditions are ...

Get Unity 5.x Animation Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.