Game Development Reference
In-Depth Information
Figure 15.29 Adjusting the trigger's
layer so they won't be seen by the
raycasting mechanism.
Make the EMP Effective
So now we can place the EMP. This visually explodes, but we need to
make it actually do something. The first thing we need to do is check if the
EMP has been placed within a certain distance of the keypad. If it has, it
needs to short the keypad out. We'll indicate that by changing the color
of the texture on the keypad, turning on some smoke, and then opening
the doors.
We can nest all of this within the ExplodeEMP function. But first we need to
create some variables to hold everything.
Step 22: Create public variables for keypadLock, keypadSmoke,
entryWayLeftDoor, and entryWayRightDoor. Place them all at the
beginning block of the script:
var keypadLock : GameObject;
var keypadSmoke : GameObject;
var entryWayLeftDoor : GameObject;
var entryWayRightDoor : GameObject;
Step 23: Down in the ExplodeEMP function, add the following code:
function ExplodeEMP(placedEMP:GameObject){
yield WaitForSeconds (2);
placedEMP.audio.enabled = true;
placedEMP.GetComponent(“Detonator”).enabled = true;
placedEMP.renderer.material.color = Color (0,0,0);
if (Vector3.Distance(placedEMP.transform.position,
keypadLock.transform.position) <= 1){.
keypadLock.renderer.material.color = Color
(.5,.5,.5);
keypadSmoke.active = true;
iTween.RotateTo (entryWayLeftDoor, Vector3
(0,45,0), 8);
iTween.RotateTo (entryWayRightDoor, Vector3
(0,-45,0), 8);
}
}
Search WWH ::




Custom Search