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 power sources


The power sources are prefabs. There are two of them already instantiated in the scene. In order to make them draggable, we simply have to use the UIDragObject component.

UICamera

First things first; we need GameCamera to have the UICamera component attached to it in order to trigger events on 3D world objects like the ground or the power sources. To get the required results, perform the following steps:

  1. Select the GameCamera GameObject.

  2. Click on the Add Component button in the Inspector view.

  3. Type in uicam to search for components with that name.

  4. Select NGUI Event System (UICamera), and hit Enter or click on it.

  5. Set the newly attached UICamera component's Event Type to 3D World.

  6. Make sure Event Mask is set to Everything and not just 2DUI.

OK. The GameCamera GameObject is now ready to trigger events on 3D objects. We can now make our power sources draggable objects.

UIDragObject

Let's use the UIDragObject component to drag our power sources in the 3D world:

  1. In the Project view...