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.
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:
uicam
to search for components with that name.UICamera
), and hit Enter or click on it.UICamera
component's Event Type to 3D World.OK. The GameCamera GameObject is now ready to trigger events on 3D objects. We can now make our power sources draggable objects.
Let's use the UIDragObject
component to drag our power sources in the 3D world:
Assets/Resources/Prefabs/PowerSource
.obj
to search for components with that name.For the newly added UIDrag Object
component on our PowerSource
prefab:
Resources/Prefabs/PowerSource
(itself) in the Target field.1
, 0
, 1
} to limit movement to the X and Z axes.OK. The Drag Object
component is configured. But, as we have learned in previous chapters, NGUI components using events need Box Collider attached to them.
For the UIDragObject
component to work, it needs to have Box Collider attached to it in order to receive UICamera
events:
Resources/Prefabs/PowerSource
.box
with your keyboard.4
, 4
, 4
}.OK, now that we have the Box Collider and the UIDragObject
components, hit Unity's play button. You can now drag-and-drop both our power sources on the scene!
Now, let's now see how we can make the player move to a clicked position on the ground or an interactive element.
18.225.95.245