Game Development Reference
In-Depth Information
Figure 15.9 The camera “seeing” the
First Person Controller.
Step 13: Make the light pulse. To do this we will make a looping function.
To create this looping function we'll create a mini-state-engine to define
the state of things. The looping function will continue to loop as long
as this state is true. So we'll need to do a few things to the script: add a
Boolean (true/false switch), define that this Boolean is true when the ray
hits the Player tag, and then fire the looping 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(){
while (seenSomething){
var textureColor : Color;
textureColor.r = Mathf.Sin (Time.time * 10.0);
renderer.material.color = textureColor;
yield;
}
}
Why?
So note the three new things. var seenSomething is the declaration of
the Boolean variable. Then in the Update function, note that we define
seenSomething as true when the ray collides with something with the tag
“Player.” Then, when seenSomething is true, we tell Unity to go fire the
function PulseLight.
PulseLight is the looping function. After defining the name of the
Search WWH ::




Custom Search