Game Development Reference
In-Depth Information
function Update () {
var hit : RaycastHit;
if (Physics.Raycast (transform.position, transform
.forward, hit, 100)){
Debug.DrawLine (transform.position, hit
.point);
Debug.Log (“Selected object is ” + hit
.collider.gameObject.name);
if (hit.collider.gameObject.name ==
“Hallway_PowerPanel_Switch”){
AddHighlight(hit.collider.gameObject);
if (Input.GetMouseButtonDown(0)){
TurnOnLights();
}
}
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?
In the area of the code that's telling Unity what to do if the name of the
object being raycast against is Hallway_PowerPanel_Switch, we're saying,
“If the user clicks the mouse button 0 (the left mouse button), go run the
TurnOnLights function.”
 
Search WWH ::




Custom Search