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

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.

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)){…}