To animate or not to animate?

Normally would try and put some serious effort into trying to solve a problem by myself before turning to the UA community, but I’m dead tired. I have a crouch animation and when I’m not hitting the “S” key I want it to play the animation in reverse.

Animation Script

#pragma strict
var crouchCheck : boolean;
function Start () {
crouchCheck = false;
}

function Update ()
 {
	if(Input.GetKey(KeyCode.S) && !crouchCheck )
		{
			crouchCheck = true;
			//animation["Crouch"].wrapMode = WrapMode.Once;
			animation.Play("Crouch");
			if(animation.IsPlaying("Crouch")) { print("Crouch Begins"); }

		}
	if(!Input.GetKey(KeyCode.S) && crouchCheck)
		{
			animation["Crouch"].speed = -1;
			animation.Play("Crouch");
			if(animation.IsPlaying("Crouch")) { print("Crouch ended"); }
			crouchCheck = false;
		}
}

When I hit “S”, it plays the Crouch animation perfectly and does the print. When I let go of crouch my player instantly jumps to a standing position instead of playing the animation in reverse and “Crouch ended” is printed. Then every time I hit “S” following the first semi-successful time doing the crouch(instant stand up), it doesn’t do the Crouch animation, but still prints “Crouch Begins” and prints “Crouch ended” upon release and doesn’t reverse the animation because it never did it in the first place. Am confused I? Yes.

-Crouch animation’s wrapmode is set to default

Animation.Play implicitly resets the time of the AnimationState back to 0, as it should be described in the documentation. So since your speed is negative it will reach the “end” (actually the start) of the animation instantaneously. To solve this, either don’t use the Play function and just enable the AnimationState directly, or set the time of the AnimationState back to it’s length right after you call Play.