Game Development Reference
In-Depth Information
Unity3D tutorial - part 2
In the first part of our tutorial in Chapter 8 , Mobile Game Engines , we prepared the
game scene. In this second part we will show how to make things behave properly.
Let's begin thinking about the game logic we are going to implement in our game.
In Space Invaders the player controls a ship located at the bottom of the screen, which
moves left and right and shoots bullets.
The goal is to destroy wave after wave of aliens approaching towards the player's
ship from the top half of the screen, before they reach the bottom of the screen, while
avoiding the bullets they fire.
Aliens move according to a snake-like pattern; they begin moving right and as they
reach the right boundary of the screen, they invert direction and move a little bit closer
to the bottom of the screen, then repeat the cycle as they move left and reach the left
boundary of the screen.
Once in a while, aliens shoot bullet towards the player's ship.
Player's bullets move bottom-up, while aliens' move top-down.
The player's ship
As the player's ship is easier to implement, we'll begin with it.
1. Drag the PLShip prefab into the Scene View and set its position at coordin-
ates X = 0 , Y = -15 , Z = 15 (these are arbitrary values, but they are consistent
with camera settings we defined earlier). You can edit the scale of the PLShip
prefab in case it is not the right size by changing its scale values in the Trans-
form panel in the Inspector panel.
2. We want the ship to move left and right and fire a bullet, to do that we create
a JavaScript file and add it to the PLShip prefab.
3. In the Project panel create a new folder, name it Scripts and then create a
JavaScript file in the folder. Name it ControlShip and double-click it to open
in the default script editor provided with Unity, called MonoDevelop .
Search WWH ::




Custom Search