Graphics Reference
In-Depth Information
if(isAIControlled)
{
if(collider.gameObject.layer==9 && !isRespawning &&
!isInvulnerable)
{
See the Hit() function later in this chapter to see what it does:
Hit();
}
} else {
AI-controlled player's projectiles are on layer number 17:
if(collider.gameObject.layer==17 && !isRespawning &&
!isInvulnerable)
{
Hit();
}
}
}
The race controller will check for a trigger hit between this player's collider and the
start/finish line trigger, but this script has an OnTriggerEnter function to check for trig-
gers used to force a respawn. The respawn triggers are placed on the buildings and under
the track in case the player falls off the track and into oblivion. Rather than letting the
vehicle fall forever, a hit with a respawn trigger will make a call to the Respawn() function:
public void OnTriggerEnter( Collider other )
{
A respawn trigger is a collider, set to act as a trigger, on a specific layer. respawn-
LayerMask should be set in the Unity editor Inspector window to include the layer that the
respawn object(s) is (are) on.
The code constructs its own layer mask for objLayerMask from the other Collider's
layer (other.gameObject.layer). It then checks to see whether the respawnLayerMask con-
tains the objLayerMask:
int objLayerMask = (1 << other.gameObject.layer);
if ((respawnLayerMask.value & objLayerMask) > 0)
{
Respawn() will reposition the player back on the track, facing the right way:
Respawn();
}
}
When a projectile hits a player, its Hit() function is called to reduce the health level
held by the data manager, which checks whether the player should explode and do any
relevant effects like explosion particles or sound effects:
void Hit()
{
Search WWH ::




Custom Search