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)

Enemy spawning


We want our enemies to spawn at the top of the viewport's background. At spawn, the Y value can be the same for each of the enemies, but we want a random X value.

First of all, let's open our Game scene.

Creating the enemies container

Our enemies will be nested in a container placed at the top left-hand corner of our background in order to have the {0, 0} positioned at the top left-hand corner of the viewport.

First, let's create our enemies holder by performing the following steps:

  1. Select our Viewport GameObject and perform the following steps:

    1. Create a new child by pressing Alt + Shift + N.

    2. Rename this new child as Enemies.

  2. Attach Anchor to it by navigating to NGUI | Attach. Then perform the following steps:

    1. Drag our Background from Viewport into the Container field.

    2. Set its Side parameter to TopLeft.

Ok, we now have our enemies container in which we will instantiate our Enemy prefab.

Creating the Enemy prefab

Let's create the Enemy prefab that will be instantiated as child of the Enemies...