Graphics Reference
In-Depth Information
}
void UpdateRacersRaceState()
{
for ( int b = 1; b <= numberOfRacers; b++ )
{
tempRC = (RaceController) raceControllers [b];
tempRC.UpdateRaceState(raceRunning);
}
}
}
12.3.3.1 Script Breakdown
The race manager has no need for system functions such as Update(), Start(), or
LateUpdate(), etc., and everything it does will be activated by calls from other scripts. For
that reason, it derives not from Monobehavior but from ScriptableObject instead:
using UnityEngine;
using System.Collections;
public class GlobalRaceManager : ScriptableObject
{
This script should always be accessed via its static variable Instance. Its constructor
ensures that only one instance of the script exists at any time by checking to see whether
its static variable named instance is null or not:
public static GlobalRaceManager Instance
{
get
{
if (instance == null)
{
instance = ScriptableObject.CreateInstance
<GlobalRaceManager>();
}
Once we are sure that instance contains a reference to an instance of Global =
RaceManager, it can go ahead and return it:
return instance;
}
}
When a race is started, the game controller calls InitNewRace() to get Global =
RaceManager ready for tracking. The parameter for this function is an integer for how
many laps the race should go on for:
public void InitNewRace( int howManyLaps )
{
Several variables of type Hashtable are used for access to the various objects that
the script will need to access. Note that we always have to declare the object type when
Search WWH ::




Custom Search