Using the Unity’s Animation System
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 theIdle
animation onto it - Select the
Darren_3D
gameobject in hierarchy, Add an Animator Component and in the Controller slot select theDarrenController
.
The yellow animation is the default one
- Add the
Walk
andThrow
animations into the controller - Make transitions between Idle and Walk with right click on the animation
- Uncheck the
HasExitTime
option in the transitions
Switching between animations
- In the Animator tab, create a new parameter of type
bool
and call itWalk
- Select the
Idle-Walk
transition, Add a new conditionWalk
astrue
- For
Walk-Idle
transition, chooseWalk
asfalse
- In the
Player
script, create and link a variable to reference theAnimator
component in children - Set the
Walk
value totrue
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