Animation not playing on game object activated by script

So I have a game object attached to a button on a panel in a canvas, and that panel is activated by pressing a key in game. The animation for that game object doesn’t play when the panel is activated in game, but if I have the panel activate when the game starts it plays fine. Why would the animation be messed up by this?


I’m thinking that the panel is disabled when you start the game,

so no scripts on it are loaded which is default behaviour.

This way it cannot register your keystroke.

You will have to seperate the script from the deactivated object.

You need to edit an animation frames in Animation window [first select an animation object]. It is because You want to animate the Image component and animation is attached to the SpriteRenderer component.

It looks like you are trying to make a panel manager.
There is an asset called Woo Panels. It is a professional solutions. It does all the animations and even more! Check it out! Here is the forum thread.