Game Development Reference
In-Depth Information
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?
That's a long line of code, so let's look at what's happening there.
iTween.RotateTo is calling up the custom class RotateTo that
iTween provides. Then, hit.collider.gameObject is the object
being rotated (in this case it's the power switch that the ray is
casting upon). Then are the Hashtable Args. The format for these is
argumentToChange : value, so in order these arguments are saying
“rotate to X = 0 (“x”:0) , do it over 1 second (“time”:1) , when
done look back to the object the script is attached to, not the object
you were rotating ( “oncompletetarget”:gameObject ), and when
you're done, fire the TurnOnLights function (“oncomplete” :
“TurnOnLights”).” Cool power in one line of code.
Tips and Tricks
If you're using your own version of the hallway, you may need to take some
special notes on the rotation of the power switch. The power switch of the
unlit version should begin the game rotated down; but should rotate up so
it ends the animation at the rotation of the power switch in the lit version.
Step 25: Turn the flashlight off automatically when the big lights come on.
var hallwayBaked: GameObject;
var hallwayDark: GameObject;
var flashlight : GameObject;
function Update () {
var hit : RaycastHit;
if (Physics.Raycast (transform.position, transform
.forward, hit, 100)){
Debug.DrawLine (transform.position, hit
.point);
Search WWH ::




Custom Search