I’m glad you were able to fix your problem. I was just about to test your way of handling legacy animations to see how can i help you better.
So, let’s explain what I did here.
I put the Animator component on a button, created an Animation Controller and attached it to the button.
Don’t mind the Transitions from the Button component, that was just to test how those are working.
I added a function to the Button component that requires an Animator parameter. This is the function called when pressing the button :
public void MainButtonClicked(Animator currAnimator)
{
currAnimator.SetBool("Activated", !currAnimator.GetBool("Activated"));
}
The Animator has a Parameter of type Bool (bottom left corner)
After you add the controller to the Animator component, when you create an animation from the Animation window (like you did before), it’s gonna show up in the Animator as a state, not connected to anything. The orange state is the default one.
There are 3 states in which this button can be : Normal, Activated, Activated Rev ( it’s another animation, but i used the Activated animation with speed -1 to reverse its effect )
From Normal to Activated, the Condition is for Activated to be True;
From Activated to Activated Rev, the Condition is for Activated to be False
From Activated Rev to Normal, the Condition is left default (Exit time)
Make sure the animations are not in a loop (Click the animation in the project, then in the Inspector uncheck Loop property).
That should do the job. When you first press the button, the Activated parameter will become true, it will go into Activated state (will play that animation and will stay there). When you press the button again, it will go into Activated Rev state (play the other animation). After then 2nd animation is complete, it will go back to Normal state.