Graphics Reference
In-Depth Information
there is no script attached to the same gameObject with the function PlayerFinishedRace(), the
parameter SendMessageOptions.DontRequireReciever is used, which means that no errors or
warnings will occur if there is no script to receive the message:
gameObject.SendMessageUpwards("PlayerFinishedRace",
finalRacePosition, SendMessageOptions.DontRequireReceiver);
}
At RaceStart(), our internal state variables isFinished and raceRunning are set to
false. Note that raceRunning starts out false because it will be set by another function, a
little further on from the initialization of this script:
public void RaceStart ()
{
isFinished=false;
raceRunning=false;
}
Other scripts may need to know whether this player has finished racing. The
IsFinished() function will return a Boolean to that effect:
public bool IsFinished ()
{
return isFinished;
}
When other scripts need to find out what the player's current lap is, the GetCurrentLap()
function gets the latest information to be calculated by the GlobalRaceManager object
instance. It passes in this player's ID as a parameter (so that the global race manager
knows who is asking for their lap count) and adds 1 because the return value from
GlobalRaceManager.Instance.GetLapsDone() will be how many laps are completed, not
what the current lap is:
public int GetCurrentLap ()
{
return GlobalRaceManager.Instance.GetLapsDone(myID) +1;
}
The game could be reset by another script, calling for the lap counter for this player to
be reset, too. The GlobalRaceManager object provides the ResetLapCount() function for
this, with its parameter being the player's unique ID from myID:
public void ResetLapCounter()
{
GlobalRaceManager.Instance.ResetLapCount(myID);
}
This race controller script tracks where the player is on the track by monitoring its
progress along a path of waypoints. In the example game here, those waypoints are the
same ones used to drive the AI players around. By keeping tabs on the waypoints, this
script may be accessed to find out where the car is and compare it to where other cars are
and calculate race positions. GetCurrentWaypointNum() will return the player's current-
WaypointNum integer typed variable:
Search WWH ::




Custom Search