An Animator controller helps you control character or object animations in Unity. It decides which animation plays and when.
Animator controller in Unity
Animator animator = GetComponent<Animator>(); animator.SetTrigger("Jump"); animator.SetBool("IsRunning", true);
Animator is a component attached to your GameObject.
Use parameters like triggers, bools, floats, or ints to control animation states.
Animator animator = GetComponent<Animator>();
animator.SetTrigger("Jump");Animator animator = GetComponent<Animator>();
animator.SetBool("IsRunning", true);Animator animator = GetComponent<Animator>(); float speed = 5.0f; animator.SetFloat("Speed", speed);
This script gets the Animator component and controls animations based on keyboard input. Pressing space triggers a jump animation. Holding left shift sets running animation.
using UnityEngine; public class SimpleAnimatorController : MonoBehaviour { private Animator animator; void Start() { animator = GetComponent<Animator>(); } void Update() { if (Input.GetKeyDown(KeyCode.Space)) { animator.SetTrigger("Jump"); Debug.Log("Jump triggered"); } bool isRunning = Input.GetKey(KeyCode.LeftShift); animator.SetBool("IsRunning", isRunning); Debug.Log($"IsRunning set to {isRunning}"); } }
Make sure your Animator controller has parameters matching the names you use in code.
Transitions between animations happen based on conditions you set in the Animator window.
You can preview animations and transitions in Unity's Animator window to understand flow.
Animator controller manages which animation plays and when.
Use parameters like triggers and bools to control animations from code.
Animator component must be attached to the GameObject you want to animate.