Enemy Spawning

The issue I am having and I is most likely because I am calling it in the Update function every second. It does follow my script in a way, but it spawns far quicker and far more than my script should. Also this is my entire spawning script in case you want to test it.

The reason I wrote my increase the spawn rate over time script like this was because I figured it would hold together and I don’t know how to write an actually good increase over time spawning script.

var side : int;
var Enemy : GameObject;

var timeToDecrease : float;						// Time the spawner waits to spawn the next enemy
var decreaseCounter : int;						// After 4 enemies spawn, decrease time to wait

var decreaseBool : boolean = true;			// Start/Stop first spawn rate decrease
var decreaseBool2 : boolean = true;			// Start/Stop second spawn rate decrease

function Start(){
	timeToDecrease = 3;
}  
   
function Spawn(){

	// Spawn the enemy, yeild for seconds, and increase counter
	Instantiate(Enemy,transform.position, transform.rotation);
	yield WaitForSeconds(timeToDecrease);
	decreaseCounter++;
	
	// When 4 enemies have spawned increase the spawn rate by .5 seconds
	if(decreaseCounter == 4 && decreaseBool == true){
		timeToDecrease -= .5;
		decreaseCounter = 0;
	}
	
	// If the enemy is spawning every .5 seconds the stop the spawn rate decrease
	 if(timeToDecrease <= .5){
		decreaseBool = false;
	 }
	
	// Once spawn rate is at .5 seconds decrease by .1 second until it reachs .1 second for each spawn
	if(decreaseCounter == 4 && decreaseBool == false && decreaseBool2 == true){
		timeToDecrease -= .1;
		decreaseCounter = 0;
	}
	
	//	If the enemy is spawning every .1 seconds then stop decreasing spawn rate
	 if(timeToDecrease <= .1){
		decreaseBool2 = false;
	}
}

I did not read all your code because it does not look like all of it has to do with your question, but if you are just trying to spawn things according to some kind of delay all game long you could call a function in start like this

var delay : float = 10.0;

function Start()
{
Spawn();
}

then in that function you can use a “while true” to have a continues loop for the spawn of the game.

function Spawn(){
while(true)
{
Debug.Log("spawning enemy and waiting for "+delay);
yield WaitForSeconds(delay);
if(delay > 2)
delay--;
}


}

hope that helps.