Game Development Reference
In-Depth Information
OK! Attach that script to the
Death Trigger
object, play the game, run your player
off the platform and—
nothing happens
! That was pretty anticlimactic. We promised
you all kinds of player killing, yet they annoyingly continue to fall.
We need to do a few things here. First, we are going to give the player a
hitDeathTrigger
method. To do that, open up the
PlayerStateListener
script,
find somewhere sanitary, and add the following code:
public void hitDeathTrigger()
{
onStateChange(PlayerStateController.playerStates.kill);
}
Now, the player will accept the message from the trigger. However, we don't have
a
Kill
state set up yet in the
PlayerStateListener
script! Let's do that. Start by
scrolling to the
onStateChange
function. Inside the
switch
condition, add a case
for kill:
case
PlayerStateController.playerStates.kill:
break;
case
PlayerStateController.playerStates.resurrect:
break;
Now, add the exact same thing inside the
switch
statement inside
onStateCycle
.
Then, add the following code in
checkForValidStatePair
:
case PlayerStateController.playerStates.kill:
// The only state that can take over from kill is resurrect
if(newState == PlayerStateController.playerStates.resurrect)
returnVal = true;
else
returnVal = false;
break;
case PlayerStateController.playerStates.resurrect:
// The only state that can take over from resurrect is idle
if(newState == PlayerStateController.playerStates.idle)
returnVal = true;
else
returnVal = false;
break;