Play Animation With GetKey

Hello, I want to play an animation. I did a script, but it doesn’t works at all.

When I press “P” the animation plays all, only if I keep pressed “P”. But I want to play the complete animation when I pressed “P” just once.

Here’s my script:

function Update()
{
 if(Input.GetKey(KeyCode.P))
 {
 animation.Play("animationtest",PlayMode.StopAll);
 }
}

Blockquote

This is a separate script from ThirdPersonController (I’m using ThirdPersonController, too)

Any ideas?

You want to press ‘P’ only once is not it?
Then use the GetKeyUp, which detects when you release the button, causing you to not be holding the key

Link: http://unity3d.com/support/documentation/ScriptReference/Input.GetKeyUp.html

Hope this help ^^