- Home /
play animation when press key
hi i make script but it's not working, look
if(Input.GetKey("e")){
turning = true;
}
if (turning) {
animation.CrossFade ("Beetleturnright");
}
what it's wrong with this script please help
Answer by Berenger · Jun 24, 2012 at 03:15 PM
Why not this ?
if( Input.GetKey("e") )
animation.CrossFade ("Beetleturnright");
However, make sure this is in Update, that this gameObject has an animation component (enabled) and an animation clip "Beetleturnright". That timeScale isn't 0. That this script is enabled.
Answer by pheash · Jun 24, 2012 at 03:20 PM
GetKey expects a defined name as a string, unless you have "e" defined as a special key in the input settings it wont work. it works for example "jump" or "fire1". otherwise it expects a keycode. check out this page in the reference and also click on Keycode to better understand how they work: http://unity3d.com/support/documentation/ScriptReference/Input.GetKey.html
try: if(Input.GetKey(Keycode.E)){...}
Actually, a lot of them are available, like the alphabet, numbers etc. Check this, the "Button Names" section.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
How do I play an animation with the 'E' key when I enter a trigger 2 Answers
Movement animation 1 Answer
How to rig model enough to animate in unity? Just need skeleton? 4 Answers
Animation stoping!! 1 Answer