Graphics Reference
In-Depth Information
// drop out if we're not supposed to be controlling this
// player
if(!canControl)
return;
The actual input values come in from the default input controller held in the default_
input variable. The variable default_input is declared as type Keyboard_Input.
The values returned from a call to default_input.GetHorizontal() and default_input.
GetVertical() are clamped with Mathf.Clamp as a precaution, even though the keyboard
controller this example game uses should never return anything other than a number
between −1 and 1:
// grab inputs from the default input provider
horz= Mathf.Clamp( default_input.GetHorizontal() , -1, 1 );
vert= Mathf.Clamp( default_input.GetVertical() , -1, 1 );
default_input checks for the fire button, too. Next, the code checks to see whether the
fire button is pressed and whether or not firing is actually possible. The Boolean variable
canFire is standardized across the example games as a method to be set in the Unity edi-
tor Inspector window to state whether or not this player should be allowed to fire or not.
If the fire button is pressed and canFire is set to true, the function Fire() is called on
the weaponControl object. This should tell the weapon system to fire the currently selected
weapon:
// fire if we need to
if( default_input.GetFire() && canFire )
{
// tell weapon controller to deal with firing
weaponControl.Fire();
}
}
The game controller has an Invoke statement in its Start() function, which calls
StartPlayer() and, in turn, calls this GameStart() function:
public void GameStart()
{
canControl is set to true, meaning that the player now has control:
// this function is called by the game controller to tell us
// when we can start moving
canControl=true;
}
Respawning the player starts when LostLife() is called by this script's collision func-
tion. We will look at OnCollisionEnter further in this section.
When LostLife() is called, the first thing that happens is the Boolean variable
isRespawning is set to true. You may recall this from the input function earlier when input
was locked out if the player is respawning.
Search WWH ::




Custom Search