Dragging elements can be very useful and intuitive. That's where the UIDragObject
component comes in handy.
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.
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:
Click on the Add Component button.
Type
object
with your keyboard to search for components with that word.Select Drag Object and hit Enter or click on it with your mouse.
Click once again on the Add Component button.
Type
box
with your keyboard to search for components with that word.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...