2D Toolkit Forum
2D Toolkit => Support => Topic started by: asweare on May 23, 2013, 02:05:41 pm
-
I have question about my script,
I was managed to made the character move horizontally, but
it doens't work with animation.
whenever i press left or right,
character animation stop moving.
this is my script
also, how can i make the character idle when i am not pressing the button??
(i am not really a programmer, very new to the program, so if you guys can help me out it will be really great)
void Update() {
movement = Input.GetAxis("Horizontal") * moveSpeed;
movement *= Time.deltaTime;
transform.Translate(movement,0.0f, 0.0f); // move player along X axis
// move right
if(movement > 0.02f)
{
anim.Play("walk");
anim.animationCompleteDelegate = null;
walking = true;
}
// move left
if(movement < -0.02f)
{
anim.Play("walk");
anim.animationCompleteDelegate = null;
walking = true;
}
-
In 2D Toolkit 1.x, playing Play repeatedly on a clip that is playing will keep restarting it.
Do this instead:
if (!anim.IsPlaying("walk")) anim.Play("walk");
in 2D Toolkit 2.x, the behaviour is changed that calling Play on a clip that is already playing will not restart it.