Game Development Reference
In-Depth Information
Illustration 81: The four buttons of unlock puzzle arranged around the sliding door
Each one of these buttons must be switchable by the player. Therefore, we are going to reuse
SwitchableTrigger script (Listing 35 page 90) and TriggerSwitcher script(Listing 37 page 92),
which we created in section 3.4. Recall that adding SwitchableTrigger script has the function
SwitchState() , which cycles between different states and can send different messages upon
every switch. Additionally, TriggerSwitcher script gives the player the ability to activate these
triggers by pressing E key. Whenever the player switches a puzzle button, we need to perform
three tasks: fi st, we have to change the color of the switched button from red to green or vice-
versa. Second, we have to change a global state that manages all switches and tests whether
the unlock combination has been matched. Finally, we have to try to open the door, to see if
the combination worked. Th s means that the door opens automatically once the player gives
the correct combination, so he do not have to reach the door and try to open it every time.
So let's begin with the easiest part, which is changing the color of the switch. Listing 69 shows
ColorCycler
script, which simply cycles the main color of the material between the elements of a provided
array of colors.
Search WWH ::




Custom Search