- Home /
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?
Tried using getkeydown ins$$anonymous$$d?
that won't help. have you tried disabling ThridPersonController?
Answer by Unamine · Jun 15, 2011 at 10:31 AM
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 ^^
Your answer
Follow this Question
Related Questions
Unity C# Two keys pressing one after another not doing a function vice versa 0 Answers
Run Sprint animation and stop it when button is released 1 Answer
How to select an animation clip by index number? 7 Answers
Setting up Third Person Character with iClone? 1 Answer
How to Play an Animation in Unity 4.5.3? 0 Answers