Game Development Reference
In-Depth Information
Step 21: Save and return to Unity. Fix any syntax errors that pop up
in the console.
Step 22: Populate the two variables hallwayBaked and hallwayDark by
selecting the script AC_ToolFunctionalityScript (which is attached to the
First Person Controller), then (from the Hierarchy) dragging Hallway_
BakedGroup to the hallwayBaked variable in the inspector, and then
dragging Hallway_Unbaked to hallwayDark.
Step 23: Test. If you didn't accept the challenge in the last chapter of a
trigger to open the door to this closet, either create one now or hide the
closet door. Then, when you enter the closet, the power switch should
highlight when the crosshairs are over it, and if the player clicks the
mouse, the lights will turn on (actually swaps models out).
Step 24: Refine the script to turn off the flashlight and animate the
switch rotating up. We can do this with iTween, which also gives some
really powerful tools that allow for a function to be fired. To do this we'll
need to do a bit of work with what are called Hashtable Args. Replace the
TurnOnLights(); command with the following:
var hallwayBaked: GameObject;
var hallwayDark: GameObject;
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)){
iTween.RotateTo(hit.collider.gameObject, {“x”: 0,
“time”: 1, “oncompletetarget” : gameObject, “oncomplete” :
“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;
Search WWH ::




Custom Search