Advertisement
vjanomolee

ScriptSceneManager

Dec 5th, 2011
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Scene Manager Script
  2. var gameTime            = 30;
  3. static var score        = 0;
  4. static var lives        = 3;
  5. static var missleMode   =false;
  6. var ObjectsToSpawn : Transform[] ;
  7. var SpawnInterval   : float= 15;
  8. var MaxObjectsSpawned : float= 3;
  9. var MinObjectsSpawned : float= 1;
  10. private var _NextSpawn : float=1;
  11.  
  12. function Start ()
  13. { InvokeRepeating ("CountDown", 1.0,1.0); }
  14. { _NextSpawn = Time.time + SpawnInterval; }
  15.  
  16. //Game Loop
  17. function Update ()
  18. {
  19.     {
  20.         if(lives <= 0)
  21.         { Application.LoadLevel("Screen_Lose");
  22.           lives = 3;
  23.           PlayerPrefs.SetInt ("SCORE", score);
  24.           score = 0; }
  25.        
  26.         if(gameTime <= 0)
  27.         { Application.LoadLevel("Screen_Win");
  28.           lives = 3;
  29.           PlayerPrefs.SetInt ("SCORE", score);
  30.           score = 0; }
  31.        
  32.         if(Time.time >= _NextSpawn)
  33.         { int objectsToSpawn = Random.Range(MinObjectsSpawned, MaxObjectsSpawned);
  34.         for(int i < 0; i < objectsToSpawn; ++i)
  35.         { Instantiate(ObjectsToSpawn(Random.Range(0, ObjectsToSpawn.Length), transform.position. Quaternion.identity); } _NextSpawn = Time.time + SpawnInterval; }
  36.     }
  37. }
  38. //Increase the Score when the player shoots an astroid
  39. function AddScore ()
  40. { score +=1; }
  41.  
  42. //Subtract a life when the player collides with an asteroid
  43. function SubtractLife ()
  44. { lives -=1; }
  45.  
  46. //Subtract a life when the player collides with an asteroid
  47. function AddLife ()
  48. { lives +=1; }
  49.  
  50. //Subtract a life when the player collides with an asteroid
  51. function LoadMissiles ()
  52. { missleMode=true; }
  53.  
  54. // Subtract one from the game timer every second
  55. function CountDown ()
  56. { if(--gameTime == 0)
  57.     { CancelInvoke ("CountDown"); } }
  58.  
  59. //Create and Display the HUD information for the player
  60. function OnGUI ()
  61. { GUI.Label (Rect (10,10,100,20), "Score: " +score);
  62.   GUI.Label (Rect (10,25,100,35), "Lives: " +lives);
  63.   GUI.Label (Rect (10,50,100,20), "Time left: " +gameTime); }
  64.  
  65.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement