Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma strict
- static var waveSize : int = 3;
- static var noOfWaves : int = 4;
- var spawnLocation : Transform;
- var enemyPrefab : GameObject;
- var enemyPrefabSpider : GameObject;
- var spawnDelay : int = 15;
- var waveIntervalTime : int = 50;
- private var spawnBool : boolean = true; //temporary on/off spawning control
- private var endSpawningBool : boolean = false; //final long term on/off spawning control
- private var timeCount : int = 0;
- private var currentWaveCount : int = 0;
- private var completedWavesCount : int;
- private var spawnTimer : float = 0;
- private var countDown : int = 0;
- private var clockSetBool : boolean = true;
- function Start () {
- }
- function Update () {
- if(endSpawningBool == false){
- timeCount ++; //only keep counting if spawning has not completely finished
- }
- if(completedWavesCount >= noOfWaves){//If we have spawned the required number of waves, stop spawning.
- EndSpawning();
- }
- if (currentWaveCount >= waveSize){//if we have spawned a full wave,
- spawnBool = false; //stop spawning (temporarily)
- StartClock(); //start wave interval countdown
- }
- if(spawnBool == true){//only allow spawning if spawning is true, and the build panel is closed
- SpawnWave();
- }
- }
- function StartClock(){
- if(endSpawningBool == false){//interval countdown only allowed to happen if we havent entirely finished spawning
- if (spawnBool == false){ //if spawning has temporarily been turned off (should have happened at line 42)
- if(clockSetBool == true){ //next check if our clock start switch is on
- countDown = waveIntervalTime; //set the countdown to the user defined interval variable
- clockSetBool = false; //then immediately turn the clock start switch off again
- }
- countDown--;//start counting down, whilst enemies are not spawning(spawnBool is false)
- }
- if(countDown < 1){ //once zero is reached
- spawnBool = true; //turn temp spawning back on
- currentWaveCount = 0; //reset the counter for how many enemies have been spawned in current wave
- timeCount = 0;//reset timeCount and the spawnTimer and related values.
- spawnTimer = 0;
- clockSetBool = true; //turn the clock start switch back to on
- }
- }
- }
- function SpawnWave(){
- if(timeCount >= spawnTimer && currentWaveCount < waveSize){//only spawn a wave if the time elapsed has gone past whatever
- //value is currently in spawnTimer AND if the amount of enemies in the current wave has not yet reached the wave max size
- Instantiate(enemyPrefab, spawnLocation.position, spawnLocation.rotation);//create an enemy at the spawners location
- spawnTimer += spawnDelay; //add the spawn delay value onto the spawnTimer cumulatively to add a gap between enemies
- Stats_Holder.enemiesSpawned++;//increment the stats holder enemies counter for whole game
- currentWaveCount++; //increment the amount of enemies in the current wave
- if(currentWaveCount == waveSize){//if the wave have reached max
- completedWavesCount++; //increment how many completed 'waves' have been spawned
- spawnBool = false; //temp disable spawning again
- }
- }
- }
- function EndSpawning(){
- endSpawningBool = true;
- spawnBool = false;
- timeCount = 0;
- spawnTimer = 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement