Book Image

Learning NGUI for Unity

By : Charles Bernardoff (EURO)
Book Image

Learning NGUI for Unity

By: Charles Bernardoff (EURO)

Overview of this book

Table of Contents (17 chapters)
Learning NGUI for Unity
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Buttons


Let's fill up this main menu with three buttons: Play, Options, and Exit. First, let's create an empty GameObject that will hold the three buttons:

  1. Select our Main GameObject in the Hierarchy view.

  2. Create a new empty child by pressing Alt + Shift + N.

  3. Rename the new child to Buttons.

Ok. We can now create our first button.

Creating a button

Drag Simple Button (1) from our Prefab Toolbar inside our Buttons GameObject in the Hierarchy view, as shown in the following screenshot:

A new button appears in the Game view, as follows:

Select UI Root | Buttons | Control – Simple Button. Your Hierarchy view should look like this:

As shown in the preceding screenshot, our new button is composed of two GameObjects:

  • Control – Simple Button (1): The main object, with these components attached:

    • UISprite: This renders the button's sprite, set to the Button sprite

    • UIButton: This handles different button states, colors, and events

    • Box Collider: This is required to detect mouse and touch interactions

  • Label ...