Game Development Reference
In-Depth Information
Step 18: Click the Apply button up in the Prefab buttons to spread the
love to all the other LEDs in the scene.
Step 19: Adjust the CCTV-CameraSearchingScript to include turning the
Audio Source component on within the PulseLight function:
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();
}
}
}
function PulseLight(){
audio.enabled = true;
while (seenSomething){
var textureColor : Color;
textureColor.r = Mathf.Sin (Time.time * 10.0);
renderer.material.color = textureColor;
yield;
}
}
Step 20: Save and return to Unity. Fix any syntax problems.
Step 21: Test. Make adjustments to the Volume and Min Distance/Max
Distance settings on the Audio Source to make the sound do what you
want. Be sure that when a change is made, the Prefab Apply button is
pressed so all the other prefabs get the message.
Tips and Tricks
Note that when a value is changed within a component on a prefab, the
entry goes bold. This is also a powerful idea since it allows for prefabs to
be customizable within a scene. Just because a change is made to one
prefab doesn't mean it has to be propagated to the other prefabs. Each
prefab can be customized. However, in this case we want a fairly constant
sound, so as changes are made, don't forget that Prefab Apply button.
Conclusion
We will be back to this script. It sees the player and warns the player that he
has been seen; however, there currently are no consequences. We'll need to
build a timer into this mechanism so that if the player doesn't destroy the
camera within a certain amount of time, he is assumed caught/seen and loses
the game. But we'll take care of that in a future chapter.
 
Search WWH ::




Custom Search