Game Development Reference
In-Depth Information
Listing 36:
The script that controls the light based on received messages
This script must be attached to a light object, and it starts by finding the light component
and storing it in
toControl
. When it receives
SwitchOn
message, it executes
SwitchOn()
function and enables the attached light component. The opposite happens when it receives
SwitchOff
message, by disabling the controlled light component. The other script that
receives messages is
ZFlipper
. This script rotates the object to which it is attached 180
degrees around object's local z axis. This rotation is performed when the message
Flip
is
received. But why we are going to use this script? Illustration 40 shows the object we are
going to use as switch. It is clear that when this object is rotated 180 degrees around its loc-
al z axis, the texture flips upside down, resulting in an effect similar to switch movement.