How to invert the animation?

I have the elevator, which I move up and down using animation.
But I have one animation for up movement. When I want to move elevator down, I want to invert it’s speed to the negative value:

elevatorAnimation["Elevator"].speed = -1.0f;

But I can do it only while the elevator moves up, because after animation ends, I need to play it again like:

elevatorAnimation["Elevator"].speed = -1.0f;

And in this case elevator moves not from the top to down, but immediately turns at the bottom

If you also set the ‘time’ property of the animation to it’s length, it should start at the end of the animation, and play backwards.

AnimationState anim = elevatorAnimation["Elevator"];
anim.speed = -1.0f;
anim.time = anim.length;

As per the doc, (apart from doc):

Negative playback speed is only
supported when recorder is enabled.
See Animator.recorderMode.

You should better create a two state animation and for the down animation use reverse animation logic. e.g., if you have sprites like

elev1, elev2, elev 3,... elev10

for reverse animation set it as

elev10, elev9, elev8,.... elev1

and switch the state variable of the animation based on direction. like:

animator.SetFloat("direction", 1);  // go forward


animator.SetFloat("direction", 0);  // go backward