Play animation when i press a button

Hi everyone, i’m really new in the game development industry and i’m making a game (mobile) for a school project. Basically what i want to do is when i press a button it plays an animation like a cute scene of some sort. Any help will be appreciated.

Well, with cases like this it could be a good idea to use the legacy system. Assuming you already know how to work with buttons and create animations, now all you need to do is trigger it.

The first step is to remove the animator component that is automatically added when you create an animation (this usually isn’t what you would do, but in this case the animation system is going to be easier to implement.)

Now you add the animation component (again, very different from the animator component) and attach your animation. In your assets go to your animation (the little grey box with the play button on it) and in the inspector go to the gearbox settings icon and click debug. now check the legacy button and go back to your animation component on whatever you’re animating. drag the animation over to the component where it says animation. Attach a script to what you’re animating and simply insert


to the function you call when the button gets pressed. you’ll have to uncheck play automatically in the inspector so it doesn’t start going right away, and you may want to make sure your animation isn’t in loop.

if all goes well this should be all you need to start an animation at the press of a button