Hi everyone, I hope you can help me with a problem I have been having, I am trying to include a lap timer that restarts after each lap (pretty normal) using the code that I already have, I need it to simply start when it passes the first collider/sector and finish when it reaches that same one again (i.e. one full lap).
I looked up how to set up the track and got my answer from here too, my track is set up by creating 3 trigger boxes around the track, the code then checks to see the triggers had been gone through in order, once this is done the next lap begins.
this is my sectors script which checks all the sectors have been navigated (the script is placed onto all of my checkpoints/sectors
static var playerTransform : Transform;
function Start () {
playerTransform = gameObject.Find("Nissan_GTR").transform;
}
function OnTriggerExit (other : Collider) {
//check if this transform equals current checkpoint transform
if (transform == playerTransform.GetComponent(Car).sectorArray[Car.currentSector].transform) {
//do not exceed checkpoint quantity
if (Car.currentSector + 1 < playerTransform.GetComponent(Car).sectorArray.length) {
//add lap if completed all checkpoints
if(Car.currentSector == 0){
Car.currentLap++;
}
Car.currentSector++;
}
else {
//no checkpoints remain, set to 0
Car.currentSector = 0;
}
Camera.main.GetComponentInChildren(TextMesh).text = " Lap " + (Car.currentLap);
}
}
This is my one of my car scripts that is placed onto the car
var sectorArray : Transform[]; //Checkpoint GameObjects stored as an array
private static public var currentSector : int = 0; //Current checkpoint
private static public var currentLap : int = 0; //Current lap
private static public var startPos : Vector3; //Starting position
function Start(){
startPos = transform.position;
}