This article will use the Unity Animation System to set up a character to switch between walk and idle animations.
The first thing to do is add an Animator component to the character model, create an Animator Controller for the character and assign it to the Animator.
Now we can begin hooking up the animations in the Animator window, idle as the default state.
In Play Mode, the idle animation loops.
To have the Animator change from idle to walk and back idle, we will use a bool Parameter and transition to the walk animation when it is true and back to the idle animation when it is false. Also, we disable Has Exit Time to switch immediately to the other animation.
In Play Mode, we can now manually change between idle and walk animations.
In the Player script, we will reference the Animator and use the bool to know when the script should be checking if it has reached the destination.
When the destination is set, we tell the Animator to play the walk animation by setting the Walk bool parameter to true.
There are several ways to know when to change back to the idle animation. I will show two ways to do it.
The first is to check if the path generated by the Nav Mesh Agent has been completed by seeing if it has a path.
The second is to check if the character is within a set range of the set destination.
The character now transitions between the two animations.