Book Image

NGUI for Unity

By : Charles Bernardoff (EURO)
Book Image

NGUI for Unity

By: Charles Bernardoff (EURO)

Overview of this book

Table of Contents (14 chapters)

Creating draggable barriers


It is time to create our draggable barriers. The player will be able to drag-and-drop the BarrierObject prefab in the Viewport GameObject. This BarrierObject prefab will look as shown in the following screenshot:

The BarrierObject prefab

First, we need to create our BarrierObject prefab's holder that will contain the draggable object:

  1. Select our UI GameObject.

  2. Create a new child with Alt + Shift + N and rename it as Barrier.

  3. Open the Widget Tool wizard by navigating to NGUI | Open and perform the given steps:

    1. Select Sprite for the Template parameter.

    2. Select Dark sprite for the Sprite field.

    3. With our Barrier GameObject selected, click on the Add To button.

  4. Select our new barrier's Sprite (Dark) GameObject and perform the following steps:

    1. Rename it as Background.

    2. Set its Sprite Type to Sliced.

    3. Set its Color Tint to {0, 250, 250, 170}.

    4. Set its Depth value to 0.

    5. Set its Dimensions to 200 x 200.

  5. Select our Barrier GameObject.

  6. Attach a collider to it by navigating to NGUI | Attach...