The idea is to have a 2D arrow animate when I press “A”.
public class ArrowAnimation : MonoBehaviour
{
private Animator animator;
// Use this for initialization
void Start ()
{
animator = GetComponent<Animator>();
}
// Update is called once per frame
void Update ()
{
if (Input.GetKeyDown(KeyCode.A))
{
animator.SetBool("ArrowPop", true);
Debug.Log("Bum");
}
}
}
Ok. I managed to get it working using the trigger parameter.
public class ArrowAnimation : MonoBehaviour
{
private Animator animator;
// Use this for initialization
void Start ()
{
animator = GetComponent<Animator>();
}
// Update is called once per frame
void Update ()
{
if (Input.GetKeyDown(KeyCode.A))
{
animator.SetTrigger("ArrowPop");
Debug.Log("bum");
}
}
}
Now is my question. How do I make it play only once? Or atleast stop the animation after 0.5 second.
Add a transition back to Idle. The default condition on the transition will simply wait until the ArrowPop animation is done before changing back to Idle.