-
Book Overview & Buying
-
Table Of Contents
Unity Cookbook - Fifth Edition
By :
In this recipe, we’ll create a button that, when pressed, will make an image appear.
For this recipe, we have prepared the image that you need in a folder named Images in the 02_01 folder.
To create a UI Button to reveal an image, follow these steps:

Figure 2.3: Inspector properties for an image in the scene

Figure 2.4: Settings for the OnClick event handler for the button
In this recipe, you created a new scene, imported an image, and unchecked the Visible in Runtime checkbox for the image so that it would not be seen at runtime.
You added a UI Button and a new OnClick event action that executes the GameObject.SetActive() method of the GameObject drop-down list of the button, and you checked the box so that the image (unity_logo) appears when the button is clicked.
As an alternative to having the image appear when clicking on a button, the same button could be used to make an image disappear by the checkbox on the image.