- Home /
"Didn't work" is not sufficient. Did you get an error message? Learn what it means, go to the line it tells you, and fix your code.
Play Animation on keypress?
I want to play an animation on keypress any idea how I tried this but it didnt work I had all the components in the correct place.
Script (part of it)
function Update () {
if(Input.GetMouseButtonDown(1))
AnimationClip.play("recoil")
}
Please correct that script thanks!
Answer by heino-heinrich · Oct 15, 2014 at 07:35 PM
write if(Input.GetMouseButtonDown(1)){ GameObject.Find("name of the object which has the animation").animation.Play("recoil"); }
Answer by Mr_Shneebly · Dec 19, 2014 at 12:33 AM
Sorry, I had just stumbled upon this post whilst searching for something else. But this is a syntax error. You're missing an open and close bracket for the if
statement. You also needed to have the semicolon ;
at the end of the animation line.