Advertisement
rdgorodrigo

3codigos

Jul 22nd, 2015
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.72 KB | None | 0 0
  1.  
  2. #pragma strict
  3.  
  4. var checkPointArray : Transform[]; //Checkpoint GameObjects stored as an array
  5. static var currentCheckpoint : int = 0; //Current checkpoint
  6. static var currentLap : int = 0; //Current lap
  7. static var startPos : Vector3; //Starting position
  8.  
  9. function Start () {
  10. //Set a simple visual aid for the Checkpoints
  11. for (objAlpha in checkPointArray) {
  12. objAlpha.GetComponent.<Renderer>().material.color.a = 0.2;
  13. }
  14. checkPointArray[0].GetComponent.<Renderer>().material.color.a = 0.8;
  15.  
  16. //Store the starting position of the player
  17. startPos = transform.position;
  18. }
  19.  
  20.  
  21. __________________________________________________________________________________________________________________
  22.  
  23.  
  24. #pragma strict
  25. var playerTransform : Transform; //Store the player transform
  26. var theTextComponent : UI.Text;
  27.  
  28.  
  29. function Start () {
  30. playerTransform = gameObject.Find("Rabbit").transform;
  31. //Set the player transform
  32. }
  33.  
  34. function OnTriggerEnter (other : Collider) {
  35. //Is it the Player who enters the collider?
  36. if (!other.CompareTag("Player"))
  37. return; //If it's not the player dont continue
  38.  
  39. //Is this transform equal to the transform of checkpointArrays[currentCheckpoint]?
  40. if (transform == playerTransform.GetComponent(CarCheckpoint).checkPointArray[CarCheckpoint.currentCheckpoint].transform) {
  41. //Check so we dont exceed our checkpoint quantity
  42. if (CarCheckpoint.currentCheckpoint + 1<playerTransform.GetComponent(CarCheckpoint).checkPointArray.length) {
  43. //Add to currentLap if currentCheckpoint is 0
  44. if(CarCheckpoint.currentCheckpoint == 0)
  45. CarCheckpoint.currentLap++;
  46. CarCheckpoint.currentCheckpoint++;
  47. } else {
  48. //If we dont have any Checkpoints left, go back to 0
  49. CarCheckpoint.currentCheckpoint = 0;
  50. }
  51.  
  52. visualAid(); //Run a coroutine to update the visual aid of our Checkpoints
  53. //Update the 3dtext
  54. theTextComponent.text = "Checkpoint: "+(CarCheckpoint.currentCheckpoint)+" Lap: "+(CarCheckpoint.currentLap);
  55. }
  56. }
  57.  
  58. function visualAid () {
  59. //Set a simple visual aid for the Checkpoints
  60. for (objAlpha in playerTransform.GetComponent(CarCheckpoint).checkPointArray) {
  61. objAlpha.GetComponent.<Renderer>().material.color.a = 0.2;
  62. }
  63. playerTransform.GetComponent(CarCheckpoint).checkPointArray[CarCheckpoint.currentCheckpoint].GetComponent.<Renderer>().material.color.a = 0.8;
  64. }
  65.  
  66.  
  67.  
  68.  
  69. ______________________________________________________________________________________________________________________
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76. public var scriptRef : CarCheckpoint; // Reference to the player's health.
  77. public var scriptRef2 : CarCheckpointEnemy;
  78.  
  79. var restartDelay : float = 5f; // Time to wait before restarting the level
  80.  
  81.  
  82. private var anim : Animator; // Reference to the animator component.
  83. private var restartTimer : float; // Timer to count up to restarting the level
  84.  
  85.  
  86. function Awake ()
  87. {
  88. // Set up the reference.
  89. anim = GetComponent (Animator);
  90. }
  91.  
  92.  
  93. function Update ()
  94. {
  95. // If the player has run out of health...
  96. if(CarCheckpoint.currentLap == 2)
  97. {
  98. // ... tell the animator the game is over.
  99. anim.SetTrigger ("Win");
  100.  
  101.  
  102. if(CarCheckpointEnemy.currentLap == 2)
  103. {
  104. anim.SetTrigger ("Lose");
  105.  
  106.  
  107.  
  108. {
  109. // .. increment a timer to count up to restarting.
  110.  
  111. restartTimer += Time.deltaTime;
  112.  
  113. // .. if it reaches the restart delay...
  114. if(restartTimer >= restartDelay)
  115. {
  116. // .. then reload the currently loaded level.
  117. Application.LoadLevel("Menu");}
  118.  
  119. }
  120.  
  121.  
  122. }
  123. }
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement