In this recipe, we show you how to add animation clips to the animator component of a game object (our game character). This being done, we will be able to set the transitions between the clips and create the logic for the animations to be correctly played.
First of all, we need a set of animation clips, imported in Unity and configured in Inspector. We explained these operations in Chapter 1, Importing 3D Models and Animations, so we suggest going back to it in case you haven't checked that part yet. As usual, we provide the Assets
folder you need, in case you don't have your own to use.
Before we proceed, be sure you have these four animation clips imported into your Unity project as FBX files: Char@Idle
, Char@Run
, Char@Jump
, and Char@Walk
.
The first operation is to create a folder to store the Animator Controller.
Assets
folder and create a new folder for the Animation Controller. Name this folder Animators
.Animators
folder, create a new Animator
Controller
option by navigating to Create | Animator Controller, as shown in the following screenshot:Character_Animator
, or any other name you like.Character_Animator
to open the Animator panel in Unity. Refer to the following screenshot; you should have an empty grid with a single magenta box called Any State:Models/Animations
folder and select Char@Idle
. Expand its hierarchy to access the actual animation clip named Idle
; animation clips are represented by small play icons. Refer to the following screenshot for more clarity:Jump
, taken from the Char@Jump
FBX file. The following screenshot shows what should appear in the Animator window:By dragging animation clips from the project panel into the Animator editor, Mecanim creates a logic state for each of them. As states, the clips are available to connect through transitions and the animation tree of the character can come to life.
With the Idle and Jump animations added to the Animator window, we can define the logic to control the conditions to switch between them.
In the following recipe, we create the transition to blend between these two animation clips.
3.143.247.125