Game Development Reference
In-Depth Information
Not evaluated
else if Alpha6 key pressed
Not evaluated
else if Alpha7 key pressed
Evaluates subsequent code . . .
Any efficiencies you can introduce to your code reduces the processing load, improving overall
game performance.
Cannon Zone
You created a cannon in Chapter 8, so the next step is to make it a prefab. In the Project panel, open
the Assets ➤ Prefab folder. In the Hierarchy, select the Cannon game object. Drag and drop it into
the Prefab folder. Delete the Cannon game object from the Hierarchy view.
Just as you did for the Land Mine Zone, think about how you are going to populate this zone with
the cannons. This time you have two dimensions to work with in the placement of the cannons:
along the z-axis as the player progresses through the zone, and along the y-axis at varying heights
relative to the player character. By varying the heights, the player can add utilizing the player
character's “crouching” animation to avoid the hazards.
You can manually position the cannons by dragging them from the Prefab folder and dropping them
into the Scene view, then setting the Transform position coordinates to your liking. As an alternative,
you can also use scripts to populate the scene with game objects such as hazards. For example,
create a script that directs a random distribution of cannons throughout the zone.
In the Project panel, open the Assets ➤ Scripts folder and create a new script named
RandomCannonPositions. Open it in MonoDevelop and edit the code to the following:
#pragma strict
public var prefab : GameObject;
public var amount : int = 10;
function Start () {
for (var i : int = 0; i < amount; i++)
{
var position: Vector3 = Vector3(5, Random.Range(9.0, 11.0),
Random.Range(44, 53));
Instantiate(prefab, position, Quaternion.Euler(0, 0, 90));
}
}
 
Search WWH ::




Custom Search