Game Development Reference
In-Depth Information
Listing 69: A script that cycles the color of the object
Now all we have to do is to attach SwitchableTrigger script to each button (or easier: make
a button prefab) and set the number of states to 2. When each state is activated, it sends
CycleColor message to itself. Next we have to add ColorCycler script to the button and add
red and green to colors using the inspector. Our button is now ready and cycles between red
and green colors when switched. We have to have four copies of this button in the scene,
and find a method to combine their states logically to form a puzzle. The puzzle itself can
be any script that runs any logic we want, given that it sends UnlockAll to CentralLock script
when certain condition is met. For our specific puzzle, we need a script that compares the
colors of the four buttons with an internally stored unlock sequence of colors. If the colors
match the sequence, UnlockAll message is sent to CentralLock , otherwise LockAll message is
sent. This script is ColorCodePuzzle shown in Listing 70.
Search WWH ::




Custom Search