Play animation from animator?

Hi, im making an ingame cut scene where a man dies, he has an animator controller set up and his idle animation is his default animation
i was wondering if it was possible to make an animation within the animator controller play if a button is pressed,
so he plays his die animation once i press the Q button

this is my current script, although it does not work

#pragma strict

function Update () 
    if (Input.GetButtonDown("Q"))
		animation.Play("die", PlayMode.StopAll);

sorry if this sounds confusing
Thanks in advanced

Your code looks good except where it says

animation.Play("die", PlayMode.StopAll);

Try just using:


I haven’t ever written it the way you have there so for all I know it actually does work.
Something you need to check is go into the debug menu and check to make sure “Legacy” is checked (if on Unity 5). Also make sure the Q button has been setup in your project settings.

Other than that pressing the Q button should work.