How do I reverse a animation mid way?

138206-screenshot-68.png

I have a sliding door with a simple trigger bool138207-screenshot-69.png

When the opening animation is playing and the bool turns of i want to make the animation play backwards from were it left of, right now it just snaps to the closing animation.

138212-screenshot-70.png

After some time i found out “Normalized Time” on the state and used it to scroll thru the animation.

This is the code i used.

private void Update()
{
    if (colliding && GotItem())
        progress += Time.deltaTime * animationSpeed;       
    else
        progress -= Time.deltaTime * animationSpeed;

    progress = Mathf.Clamp(progress, 0f, 1f);
    animator.SetFloat(parameterName, progress);
}