Book Image

Unity Animation Essentials

By : Alan Thorn
Book Image

Unity Animation Essentials

By: Alan Thorn

Overview of this book

Table of Contents (14 chapters)
Unity Animation Essentials
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Invoking functions from animations


Frequently, you'll need to link animations with the script and game logic. Specifically, when animation playback reaches a specific frame or time, or when an animation begins or ends, you may want something else to happen in script, even on a completely different object. In the camera fly-through animation for example, we may want to show a message on the screen saying "Welcome!", when the fly-through animation ends. There are many ways to handle this type of requirement. One way is to run a function in script when a frame shows up in the animation. To create this kind of connectivity between animation and script, we'll need an animation event.

Note

The complete Unity project for an animation event is included in this book's companion files in the Chapter03/AnimationEvents folder.

To get started with calling functions from animations, create a new C# script file or edit an existing file. Add a function of any name that returns void and either; has no arguments...