Animation.Rewind Isn't Working

Hello Everyone,

I have an animation clip that opens a door. It works great. I’m having trouble closing the door. Instead of creating an animation clip that closes the door I noticed there’s an animation.rewind command. It isn’t working and I was hoping one of you fine ladies/gentlemen could help me out.

Here’s my code:

public class OpenDoorTrigger : MonoBehaviour {

public bool triggered = false;

void Update(){
	if (Input.GetKeyDown(KeyCode.E) && triggered == true){
		Debug.Log("EEEEE");
		animation.Play("OpenDoor");
	}
	else if (Input.GetKeyDown(KeyCode.E) && triggered == false && !animation.isPlaying){
		Debug.Log("REWIND");
		animation.Rewind("OpenDoor");
	}

}

I did a Debug.Log test and it does Log ‘Rewind’ so animation.Rewind(“OpenDoor”); isn’t working. Does anyone know why?

I’d appreciate any feedback. Thank you for your time and have a nice day.

Animation.Rewind just sets the animation back to frame zero. You want to use play, but set the playback rate to be negative to play the animation in reverse:

void Update()
{
    AnimationState state = animation["OpenDoor"];
    if (Input.GetKeyDown(KeyCode.E) && triggered == true){
       Debug.Log("EEEEE");
       state.speed = 1.0;
       animation.Play("OpenDoor");
    }
    else if (Input.GetKeyDown(KeyCode.E) && triggered == false && !animation.isPlaying){
       Debug.Log("REWIND");
       animation.Play("OpenDoor");
       state.speed = -1.0;
       state.time = state.length;
    }
}