Game Development Reference
In-Depth Information
Laser Obstacle
For the laser obstacle you will learn to use the Line Renderer (Figure 8-12 ). The Line Renderer does
just that—draws a line between two points. It can also use an array of points, drawing segments
between each for more complex patterns.
Figure 8-12. The player character and the laser obstacle
The line itself is a 2D billboard just like the particle textures, so depending on your scene it can
appear to have a little motion as it rotates to stay facing the camera. You can adjust its width and
color, and even use a texture.
This obstacle consists of a laser emitter above the obstacle course, firing a laser downward to the
surface of the elevated track as it moves back and forth.
Laser Emitter
To simulate a laser emitter, create a primitive Cube game object in the Hierarchy, name it LaserCube,
and give it a Transform.position of (-3.8, 12, 100) and a Transform.scale of (0.2, 1, 0.2).
The LaserCube game object needs a simple script to add the movement to it. In the Project
panel Assets ➤ Scripts folder, select Create ➤ JavaScript, name it MoveLaser, and open it in
MonoDevelop. Edit the code to the following:
#pragma strict
public var speed : float = 1;
public var offset : float;
function Start () {
offset = transform.position.x - 0.2;
}
 
Search WWH ::




Custom Search