- Home /
Question by
EliteHedgehog56 · Mar 02, 2018 at 04:15 AM ·
scenefunctionsoverlaystatic variables
load winning scene when completed race
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.<Renderer>().material.color.a = 0.2;
}
checkPointArray[0].GetComponent.<Renderer>().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
Comment
Your answer
Follow this Question
Related Questions
How to close overlay panel? 1 Answer
Prevent 'Cleaning up leaked objects' 1 Answer
Android Error 0 Answers
Script Help Scene Complete Level 1 Answer
Can you add an animated scene into Unity and let it play? 1 Answer