Using Animation Events to throw an object
Now that your animated character is ready, you might want to coordinate some of her actions with her animation states. In this recipe, we will exemplify this by making the character throw an object whenever the appropriate animation clip reaches the right time. To do so, we will make use of Animation Events, which basically trigger a function from the animation clip's timeline. This feature, recently introduced to the Mecanim system, should feel familiar to those experienced with the Add Event feature of the classic Animation panel.
Getting ready
For this recipe, we have prepared a Unity Package named Throwing
, containing a basic scene that features an animated character and a prefab named EasterEgg. The package can be found inside the 1362_07_07
folder.
How to do it...
To make an animated character throw an Easter egg (!), follow these steps:
Create a new project and import the
Throwing
Unity Package. Then, from the Project view, open the mecanimPlayground...