Advertisement
GlasLarson

$p@wned

Feb 8th, 2013
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     #pragma strict
  2.      
  3.      
  4.     static var waveSize : int = 3;
  5.     static var noOfWaves : int = 4;
  6.      
  7.     var spawnLocation : Transform;
  8.     var enemyPrefab : GameObject;
  9.     var enemyPrefabSpider : GameObject;
  10.     var spawnDelay : int = 15;
  11.     var waveIntervalTime : int = 50;
  12.      
  13.     private var spawnBool : boolean = true; //temporary on/off spawning control
  14.     private var endSpawningBool : boolean = false; //final long term on/off spawning control
  15.     private var timeCount : int = 0;
  16.     private var currentWaveCount : int = 0;
  17.     private var completedWavesCount : int;
  18.     private var spawnTimer : float = 0;
  19.     private var countDown : int = 0;
  20.     private var clockSetBool : boolean = true;
  21.      
  22.     function Start () {
  23.      
  24.     }
  25.      
  26.     function Update () {
  27.     if(endSpawningBool == false){
  28.     timeCount ++; //only keep counting if spawning has not completely finished
  29.     }
  30.      
  31.      
  32.     if(completedWavesCount >= noOfWaves){//If we have spawned the required number of waves, stop spawning.
  33.      
  34.     EndSpawning();
  35.      
  36.      
  37.             }
  38.      
  39.     if (currentWaveCount >= waveSize){//if we have spawned a full wave,
  40.      
  41.                    
  42.     spawnBool = false; //stop spawning (temporarily)
  43.                    
  44.     StartClock(); //start wave interval countdown
  45.             }
  46.            
  47.     if(spawnBool == true){//only allow spawning if spawning is true, and the build panel is closed
  48.      
  49.      
  50.            
  51.             SpawnWave();
  52.                    
  53.            
  54.             }
  55.                    
  56.     }
  57.      
  58.     function StartClock(){
  59.     if(endSpawningBool == false){//interval countdown only allowed to happen if we havent entirely finished spawning
  60.      
  61.             if (spawnBool == false){ //if spawning has temporarily been turned off (should have happened at line 42)
  62.                             if(clockSetBool == true){ //next check if our clock start switch is on
  63.                             countDown = waveIntervalTime; //set the countdown to the user defined interval variable
  64.                             clockSetBool = false; //then immediately turn the clock start switch off again
  65.                             }
  66.                    
  67.             countDown--;//start counting down, whilst enemies are not spawning(spawnBool is false)
  68.            
  69.             }
  70.            
  71.             if(countDown < 1){ //once zero is reached
  72.            
  73.            
  74.                                     spawnBool = true; //turn temp spawning back on
  75.                                     currentWaveCount = 0; //reset the counter for how many enemies have been spawned in current wave
  76.                                     timeCount = 0;//reset timeCount and the spawnTimer and related values.
  77.                                     spawnTimer = 0;
  78.                                     clockSetBool = true; //turn the clock start switch back to on
  79.                                    
  80.                             }      
  81.      
  82.                     }
  83.     }
  84.                    
  85.     function SpawnWave(){
  86.      
  87.     if(timeCount >= spawnTimer && currentWaveCount < waveSize){//only spawn a wave if the time elapsed has gone past whatever
  88.     //value is currently in spawnTimer AND if the amount of enemies in the current wave has not yet reached the wave max size
  89.      
  90.            
  91.                             Instantiate(enemyPrefab, spawnLocation.position, spawnLocation.rotation);//create an enemy at the spawners location
  92.                             spawnTimer += spawnDelay; //add the spawn delay value onto the spawnTimer cumulatively to add a gap between enemies
  93.                             Stats_Holder.enemiesSpawned++;//increment the stats holder enemies counter for whole game
  94.                             currentWaveCount++; //increment the amount of enemies in the current wave
  95.                            
  96.                                     if(currentWaveCount == waveSize){//if the wave have reached max
  97.                                    
  98.                                     completedWavesCount++; //increment how many completed 'waves' have been spawned
  99.      
  100.                                     spawnBool = false; //temp disable spawning again
  101.                                     }
  102.                                                    
  103.             }
  104.     }
  105.      
  106.     function EndSpawning(){
  107.      
  108.     endSpawningBool = true;
  109.     spawnBool = false;
  110.     timeCount = 0;
  111.     spawnTimer = 0;
  112.      
  113.      
  114.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement