Mecanim Animation System
Mecanim Animation System
The mechanism animation system is the tool of Unity that manages the animation of the object. It enables smooth transitions between animation states, blending animations, and allowing developers to create lifelike movements for humanoid avatars.
Although the Mecanim animation system provides great control over animations, it is highly suggested to use it with a script to control the transitions among “animation states” when certain conditions are met. The animation system also provides blending between animations, in this case, a transition among idle, walk, and run animations. This ensures that there is no abrupt change in the avatar’s limb positions that will make an animation look clunky.
The gifs and code below shows transitions among idle/walk/run animations when the key T is pressed on the keyboard.
.gif)
.gif)
using UnityEngine;
public class Animation : MonoBehaviour
{
[SerializeField] Animator animator;
int state = 0;
private void Update()
{
if (Input.GetKeyDown(KeyCode.T))
{
state = state < 2 ? state + 1 : 0;
animator.SetInteger("animation", state);
}
}
}