Hello everyone. I created a simple 2D shooter game a while back in Flash. I used a variable called totalEnemies = 10; and at the beginning of each level I would do totalEnemies++; This was all fine and dandy when the object of the game was simply to eliminate all enemies. My Unity game however, spawns enemies continuously until X amount of cash is collected. The enemies act as kind of obstacles. With each level I want to increase the number of enemies. I’ve tried numerous things, I won’t paste all my versions of this statement, but I’ve tried implementing a sort of totalEnemies++; but depending on how I implemented it it either didn’t work or froze Unity completely. Any suggestions? I feel like I coded myself into a wall.
function LevelEnd(){
while (isSpawningEnemies) {
if(level <=5){
posX = Random.Range(-4.213592,4.336067);
yield WaitForSeconds(3);
Instantiate(enemies[0], Vector3(posX, 0.05523491, 3.545458),transform.rotation);
totalEnemies++;
}
if(level >= 6){
posX = Random.Range(-4.213592,4.336067);
yield WaitForSeconds(2);
Instantiate(enemies[1], Vector3(posX, 0.02, 3.545458),transform.rotation);
totalEnemies++;
}
if(level >= 10){
posX = Random.Range(-4.213592,4.336067);
yield WaitForSeconds(3);
Instantiate(enemies[2], Vector3(posX, .02, 3.545458),transform.rotation);
}
}
}
**EDIT
function LevelEnd(){
while (isSpawningEnemies) {
if(level <=5 && totalEnemies < level+1){
posX = Random.Range(-4.213592,4.336067);
yield WaitForSeconds(3);
Instantiate(enemies[0], Vector3(posX, 0.05523491, 3.545458),transform.rotation);
totalEnemies++;
}
if(level >= 6 && totalEnemies < level){
posX = Random.Range(-4.213592,4.336067);
yield WaitForSeconds(2);
Instantiate(enemies[1], Vector3(posX, 0.02, 3.545458),transform.rotation);
totalEnemies++;
}
if(level >= 10 && totalEnemies < level){
posX = Random.Range(-4.213592,4.336067);
yield WaitForSeconds(3);
Instantiate(enemies[2], Vector3(posX, .02, 3.545458),transform.rotation);
}
}
}