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

Preparing to script with Blend Tree animations


Throughout the previous sections, the Mecanim animator controller and its associated Blend Tree were fully configured to play a complete character animation. The different states (such as walk, run, idle, and so on) should not, however, be triggered arbitrarily. Instead, they should be triggered based on the player input through the WASD keys. To achieve this, we'll need to use a script, linking keyboard input to the Mecanim parameters. To get started, be sure that you've created a scene, you have a character, and you've assigned the Animator Controller asset to the Controller field of the object's Animator component. This ensures that the character model in the scene uses the appropriate Mecanim controller.

Assigning an Animator Controller to the character

Next, we'll need to create a C# script file that reads the player input and maps it to the controller parameters, playing the animation. To create a script, right-click inside the Project panel...