- Home /
How Do I Set The Number Of Laps?
//My Player script
var checkPointArray : Transform[]; //Checkpoint GameObjects stored as an array private static public var currentCheckpoint : int = 0; //Current checkpoint private static public var currentLap : int = 0; //Current lap private static public var startPos : Vector3; //Starting position private var moveMultiplier : int = 8; //Multiplies the Input.GetAxis movement of our player
function Start () { //Set a simple visual aid for the Checkpoints for (objAlpha in checkPointArray) { objAlpha.renderer.material.color.a = 0.2; } checkPointArray[0].renderer.material.color.a = 0.8;
//Store the starting position of the player
startPos = transform.position;
}
function FixedUpdate () { //Movement for the player (Standard Input: Arrow Keys/W,A,S,D) rigidbody.AddForce(Input.GetAxis("Horizontal")*moveMultiplier, 0, Input.GetAxis("Vertical")*moveMultiplier); }
//my checkpoint script
static var playerTransform : Transform; //Store the player transform
function Start () { playerTransform = gameObject.Find("Sphere (Player)").transform; //Set the player transform }
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);
}
}
function visualAid () { //Set a simple visual aid for the Checkpoints for (objAlpha in playerTransform.GetComponent(player).checkPointArray) { objAlpha.renderer.material.color.a = 0.2; } playerTransform.GetComponent(player).checkPointArray[player.currentCheckpoint].renderer.material.color.a = 0.8; }
[My question is ... How do i create a finishing point like for example i have 42 checkpoints, and i want 3 laps, after 3 laps i want the game to end and proceed to the next level].
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
I do a game for the school 1 Answer
stop song and play song 0 Answers
How to open a door after a numerical password? 1 Answer
how to change FoV 1 Answer