Game Development Reference
In-Depth Information
TriggerState is going to be used to specify how many states a switch can have. The number
of states is most of time 2 (on/off), but sometimes we need more than two states. Each state
has a restTime , expressed in the number of seconds. During rest time, the trigger is locked
and its state cannot be switched until rest time is over. This is useful for tasks that take time,
such as opening an electrical door. Each state has an array of TriggerMessage , the class
which is going to be used to specify what happens at every state change. Each one of these
messages has a name and a receiver, to which the message is going to be sent. The receiver
can be any game object in the scene, and it must have a script that receives the message.
In other words, at least one script attached to the receiver must have a function that has the
same name of the message.
Back to SwitchableTrigget , this script has a number of interesting variables. First variable is
an array of states (called states ). Each time the user activates the trigger, it tries to switch
to the next state in the array, and if is already in the last state, it goes back to the first state.
Second variable is a public index to specify the currently active state. This index refers to
one of the states in states array, and is increased at each switching. Finally, we have the
variable activationDistance , to specify the minimum distance between the trigger and the
player that allows the player to use it. In addition to these public variables, lastSwitchTime
stores the last time this trigger has been used, to be able to lock the trigger for the rest time
of the current state.
Search WWH ::




Custom Search