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 ();
    }

     // 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.

72897-capture.png

Here , I put the project into an archive, take a look. https://drive.google.com/open?id=0B2eF3YXmA9z3VDNyT19fRncyRUU

1 Answer

1

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.