How it works...

Animation Events call public functions from the scripts assigned to the game object playing the animation. To make it work, the Function field of the Animation Event needs to have the same name as the function we want to call from the script.

Events are extremely useful because they allow us to synchronize function calls with animations. The best moment to check if player hits the target is when we see a visual hit in the animationa fist is in its extreme position in a punch, or a sword is in its extreme position in a swing. Without Animation Events, we would have to always manually delay function calls to achieve similar results.

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.