Enemy Wave

Hey all, I’m new to Arrays and I’ve got my script spawning 1 enemy every wave but I wanted to make it so that the script will spawn +1 enemy every new wave (Wave 1 = 1, Wave 2 = 2, etc.) but I’m not sure how. Would someone mind making my script do that and explaining what they did so I can use it again in the future?

var textColor = Color.yellow;
var NumberEnemies : int;
var WaveNumber = 0;
var NewWave : boolean = false;

var SpawnPoints : Transform[];
var Enemies : Transform[];

function Awake () {
   guiText.material.color = textColor;
}

function Update(){
	NumberEnemies = ((GameObject.FindGameObjectsWithTag("Enemy").Length) - 1);
	
	guiText.text = "Wave: " +WaveNumber;
	
	if(NumberEnemies == 0 && !NewWave){
		NewWave = true;
		WaveNumber += 1;
		SpawnEnemies();
	}
}

function SpawnEnemies(){
	SpawnEnemy = Instantiate(Enemies[0],SpawnPoints[0].position,SpawnPoints[0].rotation);
	NewWave = false;
}

Just add a for loop around the spawning code:

Instead of just

SpawnEnemy = Instantiate(Enemies[0],SpawnPoints[0].position,SpawnPoints[0].rotation);

You can write

for (var i = 0; i < WaveNumber; i++) {
    SpawnEnemy = Instantiate(Enemies[0],SpawnPoints[0].position,SpawnPoints[0].rotation);
}

This will loop that piece of code as many times as the wave you’re on. Since you’ve also put your spawn locations and enemies in arrays, you can change the indexes to for example Enemies*, using the iterator for the loop (the counting variable) to spawn the enemy in location 0 of your array in the first wave, the enemies at locations 0 and 1 at the second, locations 0, 1 and 2 for the thrird wave and so forth, since the foor loop starts counting the i at 0 and continues up as long as it’s smaller than WaveNumber. For this you need to make sure to have as many added enemies in your array as waves though. =)*
Good luck!