Hello!
Sorry for my english -)
Help to write code.
Needed:
We press the key - it will become animated, release the key - the animation stops.
I wrote the code, but it does not work as expected:
When you press key the animation starts. When the key is released, it does not stop
if (Input.GetKey(KeyCode.RightArrow))// if pressed right
{
//Should play an animation running right
anim.SetFloat("Run", Mathf.Abs(runSpeed)); // Play the animation runs
transform.eulerAngles = new Vector3(0, 0f, 0); // For rotation in the opposite direction sprite
transform.Translate(runSpeed * Time.deltaTime, 0, 0); // run (runSpeed = 1f)
}
if (Input.GetKey(KeyCode.LeftArrow)) if pressed left
{
anim.SetFloat("Run", Mathf.Abs(runSpeed)); // Play the animation runs
transform.eulerAngles = new Vector3(0,180f,0); // For rotation in the opposite direction sprite
transform.Translate(runSpeed * Time.deltaTime, 0, 0); // run (runSpeed = 1f)
}
From Russia with love