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

The elemental source switch


We would like both our power sources to be switchable between these four elements:

  • Fire

  • Water

  • Ice

  • Lightning

In order to do that, we'll give the player the possibility to display the following selection menu when he or she right-clicks on a power source:

Before we implement the code to display it, we'll create the necessary buttons.

The elemental switch UI

We'll build the elemental switch UI as seen in the previous screenshot. We first create the Fire elemental button and make it a prefab in order to create the other three other buttons.

The Fire button

Let's start by creating the Fire elemental button:

  1. Select our InGame2DUI GameObject.

  2. Create a new empty GameObject with Alt + Shift + N.

  3. Rename it to ElementSwitch.

  4. In the Project view, type in button in the search box.

  5. Drag the Control – Simple Button prefab into our new ElementSwitch GameObject.

  6. Rename our new button to ElementalButton.

  7. Reset the Transform position to {0,0,0}.

OK, let's select and configure this button...