Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma strict
- 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
- 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;
- }
- __________________________________________________________________________________________________________________
- #pragma strict
- var playerTransform : Transform; //Store the player transform
- var theTextComponent : UI.Text;
- function Start () {
- playerTransform = gameObject.Find("Rabbit").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(CarCheckpoint).checkPointArray[CarCheckpoint.currentCheckpoint].transform) {
- //Check so we dont exceed our checkpoint quantity
- if (CarCheckpoint.currentCheckpoint + 1<playerTransform.GetComponent(CarCheckpoint).checkPointArray.length) {
- //Add to currentLap if currentCheckpoint is 0
- if(CarCheckpoint.currentCheckpoint == 0)
- CarCheckpoint.currentLap++;
- CarCheckpoint.currentCheckpoint++;
- } else {
- //If we dont have any Checkpoints left, go back to 0
- CarCheckpoint.currentCheckpoint = 0;
- }
- visualAid(); //Run a coroutine to update the visual aid of our Checkpoints
- //Update the 3dtext
- theTextComponent.text = "Checkpoint: "+(CarCheckpoint.currentCheckpoint)+" Lap: "+(CarCheckpoint.currentLap);
- }
- }
- function visualAid () {
- //Set a simple visual aid for the Checkpoints
- for (objAlpha in playerTransform.GetComponent(CarCheckpoint).checkPointArray) {
- objAlpha.GetComponent.<Renderer>().material.color.a = 0.2;
- }
- playerTransform.GetComponent(CarCheckpoint).checkPointArray[CarCheckpoint.currentCheckpoint].GetComponent.<Renderer>().material.color.a = 0.8;
- }
- ______________________________________________________________________________________________________________________
- public var scriptRef : CarCheckpoint; // Reference to the player's health.
- public var scriptRef2 : CarCheckpointEnemy;
- var restartDelay : float = 5f; // Time to wait before restarting the level
- private var anim : Animator; // Reference to the animator component.
- private var restartTimer : float; // Timer to count up to restarting the level
- function Awake ()
- {
- // Set up the reference.
- anim = GetComponent (Animator);
- }
- function Update ()
- {
- // If the player has run out of health...
- if(CarCheckpoint.currentLap == 2)
- {
- // ... tell the animator the game is over.
- anim.SetTrigger ("Win");
- if(CarCheckpointEnemy.currentLap == 2)
- {
- anim.SetTrigger ("Lose");
- {
- // .. increment a timer to count up to restarting.
- restartTimer += Time.deltaTime;
- // .. if it reaches the restart delay...
- if(restartTimer >= restartDelay)
- {
- // .. then reload the currently loaded level.
- Application.LoadLevel("Menu");}
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement