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

Draggable windows


Dragging elements can be very useful and intuitive. That's where the UIDragObject component comes in handy.

UIDragObject

UIDragObject easily makes any UI element or other GameObject in the scene draggable with both mouse and touch.

Just like all NGUI interactive components, it requires a collider to detect the mouse or touches. That collider defines the area in which the player must click to start the drag.

Usage

Let's add the UIDragObject and Box Collider components to our two windows. In Hierarchy, select both our UI Root | Main and Options GameObjects, and then:

  1. Click on the Add Component button.

  2. Type object with your keyboard to search for components with that word.

  3. Select Drag Object and hit Enter or click on it with your mouse.

  4. Click once again on the Add Component button.

  5. Type box with your keyboard to search for components with that word.

  6. Select Box Collider and hit Enter or click on it with your mouse.

OK, we've just added the UIDragObject and Box Collider components to our...