Game Development Reference
In-Depth Information
Tips and Tricks
Just a side note, if we wanted it to do something only if the Boolean was
false, it would look like this: if (!destroyWhenFinished){
Step 27: Save and return to Unity. Fix any syntax errors that pop up in the
console.
Step 28: Select Trigger-BulkheadDoor1 and look at the Inspector
( Figure 13.13 ). Here is where the Door (Hallway_Door_Bulkhead_Group)
is populated and the Door Open Sound (Sound-DoorOpenBulkhead1) is
populated by dragging those GameObjects from the Inspector to their
respective variable location. Lastly, notice the Destroy When Finished
boolean is available there to be checked (or not, if the trigger is meant to
be reused).
Figure 13.13 Populated
variables for our new
HallwayDoorsTriggerScript.
Step 29: Test. To see if the destroy is happening, make sure the Hierarchy
panel is still opened and watch what happens to the trigger after it is
tripped the first time.
Step 30: Further allow the script to be customized by exposing a variable
to control the angle to which the door angles. Adjust as follows, save it,
and then return to Unity to see the results in the Inspector for Trigger-
BulkheadDoor1:
var door : GameObject;
var doorOpenSound : GameObject;
var destroyWhenFinished : boolean;
var openAngle : float;
function OnTriggerEnter (other:Collider){
iTween.RotateTo(door.gameObject,
Vector3(0 ,openAngle, 0), 5.0);
doorOpenSound.audio.Play();
yield WaitForSeconds (doorOpenSound.audio.clip
.length);
Search WWH ::




Custom Search