I got this script that goes along with a checkpoint script, it has a static variable that counts how many laps the player has completed, what I want to do is load a winning scene or overlay when the player completes 3 laps, I tried using the update function but when the player completes the lap goal the script continues loading the next scene and makes the game unplayable? is there a better function I can use ?
here's the script:
import UnityEngine.SceneManagement;
var checkPointArray : Transform[]; //Checkpoint GameObjects stored as an array
static var currentCheckpoint : int = 0; //Current checkpoint
static var currentLap : int = 0; //Current lap
static var startPos : Vector3; //Starting position
var checkpointText : UI.Text;
var lapText : UI.Text;
function Start () {
//Set a simple visual aid for the Checkpoints
for (objAlpha in checkPointArray) {
objAlpha.GetComponent.().material.color.a = 0.2;
}
checkPointArray[0].GetComponent.().material.color.a = 0.8;
//Store the starting position of the player
startPos = transform.position;
}
function Update(){
if(checkpointText)checkpointText.text = currentCheckpoint.ToString();
if(lapText)lapText.text = currentLap.ToString();
}
// load next scene or show game over overlay when the set number of laps is completed
↧