Game Development Reference
In-Depth Information
if (hit.collider.gameObject.name ==
“Hallway_PowerPanel_Switch”){
AddHighlight(hit.collider.gameObject);
}
if (hit.collider.gameObject.name ==
“Hallway_Key”){
AddHighlight(hit.collider.gameObject);
}
}
}
function AddHighlight(hiOb:GameObject){
hiOb.renderer.material.color.r = hiOb.renderer
.material.color.r*10;
hiOb.renderer.material.color.g = hiOb.renderer
.material.color.g*10;
hiOb.renderer.material.color.b = hiOb.renderer
.material.color.b*10;
yield WaitForSeconds (0.1);
hiOb.renderer.material.color.r = hiOb.renderer
.material.color.r/10;
hiOb.renderer.material.color.g = hiOb.renderer
.material.color.g/10;
hiOb.renderer.material.color.b = hiOb.renderer
.material.color.b/10;
}
function TurnOnLights(){
hallwayBaked.SetActiveRecursively(true);
hallwayDark.SetActiveRecursively(false);
Destroy(hallwayDark);
}
Why?
At the beginning of the script we declare two public variables ( hallwayBaked
and hallwayDark ). Then at the end of the script we create a new function
( TurnOnLights ) that uses the SetActiveRecursively function. This
means that an object and all of its children are set active (or inactive).
Note that what's happening there is that the lit version is all turned on,
and then the dark version is all turned off. Finally, since the lights are
going to stay on, we can destroy the unlit version of the hallway so
we needn't deal with it later or keep it in the dataset that Unity is
working with.
Step 20: Define when the TurnOnLights function is to fire. We'll want
this to happen on a mouse click, but only when the power switch is
highlighted. Add the following code:
var hallwayBaked: GameObject;
var hallwayDark: GameObject;
 
Search WWH ::




Custom Search