- Home /
When 2 buttons pressed animation stops?
Hey, So im doing a walking animation. I currently use this script to make it loop when holding the buttons down.
#pragma strict
function Update()
{
if(Input.GetKey(KeyCode.W))
animation.Play("walk");
if(Input.GetKey(KeyCode.S))
animation.Play("walk");
if(Input.GetKey(KeyCode.A))
animation.Play("left");
if(Input.GetKey(KeyCode.D))
animation.Play("right");
else if(!Input.anyKey)
animation.Play("idle");
}
However when i press 2 of the buttons down such as D & S It just freezes the animation and doesn't play anything?
This is obviously because the two animations are conflicting when trying to play but How can i get around this?
Thanks
Answer by tanoshimi · Jun 15, 2014 at 09:31 PM
Change your subsequent if
statements to else if
statements, so that only one gets executed?
Thats a great suggestion! Didn't think of that haaha, Thankyou so much it worked :)
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Stop a animation loop after a certain amount of plays? 1 Answer
Problem with animation. 1 Answer
Making an animation stop once it finishes (trouble with booleans) 1 Answer
How do i loop animation 1 Answer