Using the Unity’s Animation System

Hernando Nieto Jaramillo
2 min readAug 4, 2021

--

As explained here, Unity’s animation system is based on the concept of Animation Clips, which contain information about how certain objects should change their position, rotation, or other properties over time.

In the previous blog, the player was set up as a capsule

Now we will disable the capsule’s mesh renderer and add the Darren 3D prefab into the player

  • Create an Animator Controller, name it DarrenController

An Animator controller manages the various Animation Clips and the Transitions between them using a State Machine

  • Select the DarrenController Animator, double click and drag the Idle animation onto it
  • Select the Darren_3D gameobject in hierarchy, Add an Animator Component and in the Controller slot select the DarrenController.

The yellow animation is the default one

  • Add the Walk and Throw animations into the controller
  • Make transitions between Idle and Walk with right click on the animation
  • Uncheck the HasExitTimeoption in the transitions

Switching between animations

  • In the Animator tab, create a new parameter of type bool and call it Walk
  • Select the Idle-Walk transition, Add a new condition Walk as true
  • For Walk-Idle transition, choose Walk as false
  • In the Player script, create and link a variable to reference the Animator component in children
  • Set the Walk value to true when click on left mouse button
public Animator animator;
void Start(){
animator = GetComponentInChildren<Animator>();
}
void Update(){
if (Input.GetMouseButtonDown(0)){
if (Physics.Raycast(rayOrigin, out hitInfo)){
animator.SetBool("Walk",true);
}}

This way the Player will pass from Idle to Walk animation

--

--

No responses yet