Animating a button when the cursor is over it
In this recipe, you will learn how to animate a button when the cursor is over it. You will also learn how to use an Animator controller to handle generated animations from the Button (Script) component and how to change these animations.
How to do it...
First of all, we have to create a UI button. Right-click on the Hierarchy panel, then go to UI | Button, and rename it Animated Button. Of course, it is possible to resize, change Source Image, the text, and place it as we wish.
Now, we need to change the Transition mode in order to use a controller to animate it. In the Button (Script) component, click on Transition and select Animation. If you don't want to create a controller from scratch, click on the Auto Generate Animation button that has just appeared in the Inspector, as shown here:
Now, Unity will ask us where to save the new controller, and we have to give it a name. Let's choose a folder in our Project, rename it AnimatedButton.controller...