Unity Quick Tips
Animation Events in Unity
//Controlling script from an animation
Often in game we need to create behaviors that occur at certain moments during an animation. This might seem like a very difficult task. However once again Unity to the rescue with Animation Events.
An animation event is pretty straight forward. It allows us to trigger a code in script at a key moment in the animation. For example, the spider attack above is triggering the projectile acid using animation Events.
Adding the event is pretty simple. In the Animation Window, select the key frame you want the animation event to occur and hit the highlighted button. This will add an event keyframe. In the inspector you can now set the method to be called in the dropdown.
There is one important thing to remember. The method you want to call has to be in a script on the same game object as the Animator or can not see it. This may require notification scripts if you are using a hierarchal approach to your design. You can set as many event frames as you want and now have the power to drive your game forward using animations.