Making a button that changes color

In this recipe, we will see the first basic customization that we can allow the player to do. This customization will allow him to change the color of a button by clicking on it, and then switch between two colors. In this way, you will learn how it is possible to use events to customize buttons when the player interacts with them.

How to do it...

  1. In the first step, we have to create our UI button. Right-click on the Hierarchy panel, then go to UI | Button, and rename it to ChangeColorButton. Of course, it is possible to resize the button, change Source Image, the text, and place it as we wish in Canvas.
  2. Now, it's already time to write our script to handle the whole process. Select ChangeColorButton and, in the ...

Get Unity UI Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.