Game Development Reference
In-Depth Information
Laser Zone
You can apply many of the previous approaches to populating the Laser Zone with hazards—regular
spacing, random spacing, stationary lasers, or changing speeds, for example. In this case you will
start with lasers at regular 0.5-unit spacing down the length of the zone, moving across the width of
the elevated track at different speeds.
First make the laser hazard prefab by dragging the LaserCube game object from the Hierarchy to the
Assets ➤ Prefab folder in the Project panel and name it Laser. Delete the LaserCube game object
from the Hierarchy.
In the Project panel, open the Assets ➤ Scripts folder and create a new script named Laser Layout.
Edit the code to the following:
#pragma strict
public var prefab : GameObject;
public var zPos : float = 91.0;
public var numberLength : int = 16;
function Start () {
for (var i : int = 0; i < numberLength * 2; i++)
{
var position: Vector3 = Vector3(-3.8, 12, zPos);
Instantiate(prefab, position, Quaternion.identity);
zPos = zPos + 0.5;
}
}
Breaking this down:
(1) public var prefab : GameObject;
1.
The public reference variable of type GameObject to hold the reference to the
prefab game object.
(2) public var zPos : float = 91.0;
Declare the public variable zPos of type float and assign it the value of the
beginning of the zone.
2.
(3) public var numberLength : int = 16;
Declare the public variable numberLength of type float and assign it the value
of the length of the zone.
3.
(4) for (var i : int = 0; i < numberLength * 2; i++)
 
Search WWH ::




Custom Search