Game Development Reference
In-Depth Information
For this script we have reused
TriggerMessage
small class we have created earlier in section
3.4 (Listing 35 page 90). Th s time we have two arrays of messages:
matchMessages
,
which we send when colors match unlock code, and
mismatchMessages
, which we send oth-
erwise.
unlockCode
is directly provided as an array of colors that can be set from the inspector,
while other colors that user change come from different renderers. These renderers are refer-
enced through
colorSources
array. To bind the four buttons with the puzzle, we have to
reference their renderers as
colorSources
. Whenever a button is switched, it must fi st
switch its color and then send
CompareCodes
message to the puzzle. For simplicity, we attach
ColorCodePuzzle
to the same object of
CentralLock
. The fi al confi tion of each button, as
well as the central lock and the puzzle is shown in Illustration 82. It is remember to notice
that colors of the unlock code and the buttons must match perfectly in terms of color de-
gree: not any green matches any green, but the numeric values of the colors must be the
same. The fi al functional demo can be found in
scene20
in the accompanying project.