hi guys i trying to make my player object to collide with the cube object which by right will print out laps 1 on the race track .but there an error which said "array index is out of range"and i can’t figure out why can anyone help me?
here is the script for cube object:
function OnTriggerEnter (other : Collider) {
//Is it the Player who enters the collider?
if (!other.CompareTag("Player"))
return; //If it's not the player dont continue
//Is this transform equal to the transform of checkpointArrays[currentCheckpoint]?
if (transform==playerTransform.GetComponent(player).checkPointArray[player.currentCheckpoint].transform) {
//Check so we dont exceed our checkpoint quantity
if (player.currentCheckpoint+1<playerTransform.GetComponent(player).checkPointArray.length) {
//Add to currentLap if currentCheckpoint is 0
if(player.currentCheckpoint==0)
player.currentLap++;
player.currentCheckpoint++;
} else {
//If we dont have any Checkpoints left, go back to 0
player.currentCheckpoint=0;
}
visualAid(); //Run a coroutine to update the visual aid of our Checkpoints
//Update the 3dtext
Camera.main.GetComponentInChildren(TextMesh).text = "Checkpoint: "+(player.currentCheckpoint)+" Lap: "+(player.currentLap);
}
}