GetKeyUp not registering

I have a movement script and I want my character to turn around and move the other way rather than moonwalk backwards (forward animation playing but backward movement). This script works, but sometimes the GetKeyUp won’t register and the character will be stuck facing the wrong way and you have to play with it to get them to face the right way again. Is there a simpler or better way to do this (maybe I should use an else instead of if)? Any input is welcome, and thanks in advance.

if (Input.GetKey (KeyCode.RightArrow)) {

			animation.Play ("Allosaurus_Walk");
			rigidbody.AddForce(Vector3.right *speedH);
		}
		if (Input.GetKeyUp (KeyCode.RightArrow))
		{
			animation.Stop ("Allosaurus_Walk");
			animation.Play ("Allosaurus_Idle");
		}
		if (Input.GetKeyUp (KeyCode.LeftArrow))
		{
			animation.Stop ("Allosaurus_Walk");
			animation.Play ("Allosaurus_Idle");
			if (Input.GetKeyUp (KeyCode.LeftArrow))
			{
				transform.Rotate (0,180,0);
			}
		}
		if (Input.GetKey (KeyCode.LeftArrow))
		{
			animation.Play ("Allosaurus_Walk");
			rigidbody.AddForce(Vector3.left *speedH);
			if (Input.GetKeyDown (KeyCode.LeftArrow))
			{
				transform.Rotate (0,180,0);
			}
		}

An easier approach could be:

  • create a vector3.zero
  • depending on left or right set x to 1 or -1
  • depending on x stop if 0 and start if not
  • set the rotation. Check out Quaternion.Euler. This way you dont turn around but face the correct direction

If the code is in FixedUpdate, it must be moved to Update. KeyUp and Down events are only true for the one frame that they’re activated, and FixedUpdate may well not run that frame.