Game Development Reference
In-Depth Information
Timers on Cameras
Getting closer. We now have all sorts of ways to die. In a few pages, we will
keep track of health from level to level (right now he miraculously is healed
when he moves from the EntryWay to the Hallway). We just need to do a little
bit of cleaning up.
Currently, if the CCTV cameras see you they throw up an awful racket, but
there are no consequences. We need to add a mechanism to the cameras so
that once they see the player, a countdown begins where if it reaches 0, the
player loses the game.
Luckily, much of the mechanism already exists within the CCTV-
CameraSearchingScript. We simply need to add a CountDown function that
ends the game if the player doesn't destroy the camera.
Step 35: Open CCTV-CameraSearchingScript.
Step 36: Tell the script that when the raycast hits the object with the
tag Player, to not only fire the PulseLight function, but to also fire a new
function called CountDown:
var seenSomething : boolean;
function Update () {
var hit : RaycastHit;
if (Physics.Raycast (transform.position, transform
.forward, hit, 100)){
Debug.DrawLine (transform.position, hit
.point, Color.yellow);
if (hit.collider.gameObject.tag == “Player”){
seenSomething=true;
PulseLight();
CountDown();
}
}
}
function PulseLight(){
audio.enabled = true;
while (seenSomething){
var textureColor : Color;
textureColor.r = Mathf.Sin (Time.time * 10.0);
renderer.material.color = textureColor;
yield;
}
}
Step 37: Create a simple function that tells Unity to wait for 10 seconds,
and then launch the level Scene-ClosingFail:
var seenSomething : boolean;
function Update () {
Search WWH ::




Custom Search