Game Development Reference
In-Depth Information
The lasers all work properly now, but moving in a synchronized fashion doesn't make for much of a
challenge. To address this via code, find the MoveLaser script and open it. To randomize the speed
of each laser prefab, add the following line of code to the
Start()
function:
function Start () {
offset = transform.position.x - 0.2;
speed = Random.Range(1.0, 3.0);
}
The
Random.Range()
function should be quite familiar by now. Remember, you can always use
+' to
open its script reference documentation. You can see the random distribution of lasers in Figure
10-12
.
Figure 10-12.
The laser zone after applying random speeds to the laser prefabs
The cheat code for this zone is:
else if(Input.GetKeyDown(KeyCode.Alpha5)) {
relocationPoint = Vector3(0, 9, 90);
RelocatePlayer();
}
Add it to the list of others in the
RelocatePlayer()
function in the Cheats script.
While repositioning and reviving the character player is a handy cheat, it can be difficult to assess
everything about the hazard you want to inspect while simultaneously dodging death. Another
common and handy cheat is invincibility. To add invincibility, add the following code block to the
if
else
sequence in the
CheckInput()
function:
else if(Input.GetKeyDown(KeyCode.Alpha0)) {
player.gameObject.GetComponent(GoRagdoll).Invincibility();
}