Why is my animation not working on key press
These are the following steps I have taken to make animation to play in unity.
1) Added animation controller to the object that I want to animate. 2) Below is the code that I have written for using a particular animation.
using UnityEngine;
using System.Collections;
public class PlayerAnimation : MonoBehaviour {
private Animator anim;
// Use this for initialization
void Start () {
anim = GetComponent<Animator> ();
}
// Update is called once per frame
void Update () {
if (Input.GetKey (KeyCode.A))
{
anim.Play ("Action2", -1, 0f);
}
}
}
What else should I do to animate the game object properly.
Answer by LMan · Jun 25, 2016 at 10:03 PM
Use the animator variables to set up transitions in the controller, and then manipulate those variables through script using setbool and the like.
I understood what you have mentioned but I don’t know how to set up transitions using animator variables. Can you please help me.
You'll gain a much deeper understanding of the capabilities of the animator controller from the official learn videos on the topic.
Your answer
![](https://koobas.hobune.stream/wayback/20220612083642im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to create Mecanim animation in script from scratch? 0 Answers
Animation keys don't stay or save in animator? 0 Answers
Grid movement bug. 1 Answer