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

Customizable UI


A very interesting feature that we will add to our game is the possibility for the players to choose where their in-game UI elements are displayed. This ensures a much greater flexibility of the user interface.

The player can simply touch and hold their finger on any in-game UI element, and the game pauses and the touched element becomes draggable. The game resumes as soon as the player has dropped its UI element at their required location.

Draggable UI elements

We will use the UIDrag Object component along with Box Colliders to make our UI elements draggable. These colliders will be attached to the widgets' sprites so that their Collider auto-adjust to match option becomes available.

First, we have to add box colliders on our UI elements:

  1. Select our InGame3DUI | Score | Background GameObject:

    • In the Inspector panel, click on the Add Component button.

    • Type box to search for components with that name.

    • Select Box Collider and hit your keyboard's Enter key.

  2. Select both InGame3DUI | Score...