There seem to be problems with accessing the PlayerObject data as well as displaying the number of current checkpoints and laps.
Code for the game object ‘RaceCheckpoint’, touch this to make a checkpoint progression
public int PrevCheckNo =0; //So laps have to be obtained in order e.g the previous checkpoint has to be 1 in order to do + 1 and make this prev checkpoint a 2
void Awake ()
{
}
void OnCollisionEnter() {
if (currentCheckpoint = PrevCheckNo)
{
GameObject PlayerObject = GameObject.FindWithTag("Player");
PlayerObject.currentCheckpoint = (currentCheckpoint + 1);
}
}
Code for class ‘PlayerObject’, which is the player with all components
private static int currentCheckpoint = 0; //Current checkpoint
private static int currentLap = 0; //Current lap
public int LapTotal = 0; //How many laps in the race overall?
public int CheckpointTotal =0; // How many checkpoints in this race?
public string CurrentCheckText = "Current Checkpoint";
public string CurrentLapText = "Current Lap";
void Update ()
{
// Race Checkpoint System
if (currentCheckpoint > CheckpointTotal)
{
currentLap = (currentLap + 1); //Add a lap
currentCheckpoint =0; //Reset checkpoint total
}
if (currentLap > LapTotal)
{
//End of our turn in this race
}
}
void OnGUI() {
CurrentCheckText = GUI.TextField(new Rect(10, 10, 200, 20), CurrentCheckText: currentCheckpoint, 25);
CurrentLapText = GUI.TextField(new Rect(10, 50, 200, 20), CurrentLapText: currentLap, 25);
}
}