Game Development Reference
In-Depth Information
You can also reuse some assets to add to the challenge, such as adding land mines. You can place
them manually or create a script that distributes them, much like you did for the cannons.
In the Project panel, open the Assets ➤ Scripts folder and create a new script named
RandomLandMinePositions. Open it in MonoDevelop and add the following code:
#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(Random.Range(-3.5, 3.5),
Random.Range(8.5, 9.0), Random.Range(55, 89));
Instantiate(prefab, position, Quaternion.identity);
}
}
Breaking this down, the only differences here from the RandomCannonPositions script are the
following:
(1) var position: Vector3 = Vector3(Random.Range(-3.5, 3.5),
Random.Range(8.5, 9.0), Random.Range(55, 89));
The position x- and z-coordinate ranges reflect the width and length of the
zone along the elevated track, and the y-coordinate range varies how much
the land mine extends above the surface of the elevated track.
1.
(2) Instantiate(prefab, position, Quaternion.identity);
When the Instantiate() function is called, Quaternion.identity is the
equivalent of saying “no rotation.”
2.
Save the script, then attach it to the Hazard Setup game object in the Hierarchy. With the script
selected, open the Assets ➤ Prefab folder and drag the Land Mine prefab to the Prefab property
in the Inspector. Save the scene and playtest. You can change the number of land mines with the
amount property in the Inspector, and you can add the following cheat to the RelocatePlayer()
function in the Cheats script to get the player character back to this zone quickly:
else if(Input.GetKeyDown(KeyCode.Alpha4)) {
relocationPoint = Vector3(0, 9, 54);
RelocatePlayer();
}
As always, when you've got it tweaked the way you like it, save the scene and save the project.
Search WWH ::




Custom Search