2D Toolkit Forum
2D Toolkit => Support => Topic started by: Gnoob on June 10, 2012, 09:38:23 pm
-
I have a problem with getting the animation to play using Input.GetAxis("Horizontal").
I want the animation to play the walking animation while the user still has right or left pressed.
here is my current implementation and its not working. The animation just stops and it moves forward and will continue playing after i stop pressing the button.
void Update()
{
transH = Input.GetAxis("Horizontal") * Time.deltaTime * speed;
if (transH > 0.0f)
{
transform.Translate(transH, 0, 0);
anim.Play("walk_right");
anim.animationCompleteDelegate = null;
}
if (transH < 0.0f)
{
transform.Translate(transH, 0, 0);
anim.Play("walk_left");
anim.animationCompleteDelegate = null;
}
}
please help. thanks
-
You should only play the animation if its not playing. Calling play repeatedly, as your code will do, will make it get "stuck" on the first frame. Something like this will do the job -
if (anim.IsPlaying() && anim.CurrentClip.name != "walk_right")
anim.Play("walk_right");
-
thanks that really helped!