Game Development Reference
In-Depth Information
This script references an array of doors targetDoors and has another array of keys to unlock
them called keys . When LockAll() function is called, the script iterates over all referenced
doors and calls door.Lock() . If autoClose option is selected, every door is closed before being
locked. On the other hand, UnlockAll() function tries to unlock all doors by trying all keys
on each one of them and, if autoOpen is selected, opens them. By having multiple keys,
we can reference doors that does not necessarily have the same unlock secret text. This
can be useful for a scenario in which you wish to create a central control room with secret
entrance, and allow the player to unlock all the doors in the level from inside this room.
Otherwise, the player has to find the key for each door to unlock it. An important detail to
notice here that we reference doors through GeneralDoor script (the array targetDoors has
the type GeneralDoor[] ). This gives us the opportunity to reference multiple types of doors,
not only sliding doors.
We can now attach this script to an empty game object, and then add both parts of the slid-
ing door to its targetDoors . The second step would be adding “door2” unlock text to keys
array. We keep both autoOpen and autoClose checked, so that all we have to do to open our
sliding door is to call UnlockAll() . The question now is: who is going to call this function?
And when it is going to be called? The answer is the puzzle system we are going to build
shortly. Before introducing the programmatic details of the puzzle, let's briefly discuss its
logic. The puzzle has four buttons, which can be switched between two color states: red and
green. To unlock the door, the player must find the correct red/green combination between
these four buttons (if you are curious about the total number of possible combinations, it is
4 to the power 2 = 16). These buttons can be arranged around the door like in Illustration
81.
Search WWH ::




Custom Search