Hello!
I have a problem with velocity in 2D game.

So, I have this creature. He must go with arrows. Every arrow is an object. I wrote script, for example, for left arrow:
void Update () {
if (Input.GetKeyDown (KeyCode.Mouse0) && mouserl) {
if (TmpRange > 0) {
newTo = barmaglot.transform.position.x - 1f; // - New Position of object 'barmaglot'
Debug.Log (newTo);
// - Animation
anim.SetInteger ("Napr", 3);
anim.SetFloat ("Speed", Mathf.Abs (1));
// - And now - go!
rb.velocity = new Vector2 (-1f, rb.velocity.y);
}
}
if (barmaglot.transform.position.x < newTo) {
rb.velocity = new Vector2 (0, 0);
anim.SetInteger ("Napr", 0);
anim.SetFloat ("Speed", 0);
}
}
Works great. But.
When I click on another arrow, it stops. Code of another arrows is clone of this, but with another parameters. So, I can go only in one direction.
But Why?) I can’t understand it.