I’m making a bullet hell game (shoot-em-up with a TON of bullets), and I’m wondering if there’s a more efficient way of spawning enemies over time than what I’m doing right now.
Basically I want to spawn various waves of enemies, like enemyOne every second for five seconds, enemyTwo every second for ten seconds, stuff like that.
What I’m doing right now is having a bunch of if statements and executing the code when the current time is between two values, but is there a more efficient way of doing that? It’s just really tedious to have to redo all these if statements every time I want a new wave of enemies.
if (Time.time <= 5.0f) {
if (Time.time > nextSpawn) {
nextSpawn = Time.time + 1.0f;
GameObject enemy = Instantiate(enemyOne, new Vector3(-1400f, 0, -1500f), Quaternion.identity) as GameObject;
enemy.GetComponent<enemyOne>().setID(enemyOneCounter);
enemyOneCounter++;
}
}
if (Time.time <= 10.0f && Time.time >= 5.0f) {
if (Time.time > nextSpawn) {
nextSpawn = Time.time + 1.0f;
GameObject enemy = Instantiate(enemyOne, new Vector3(1400f, 0, -1500f), Quaternion.identity) as GameObject;
enemy.GetComponent<enemyOne>().setID(enemyOneCounter);
enemyOneCounter++;
}
}
if (Time.time <= 25.0f && Time.time >= 10.0f) {
if (Time.time > nextSpawn) {
nextSpawn = Time.time + 5.0f;
GameObject enemy = Instantiate(enemyTwo, new Vector3(0, 0, -1950f), Quaternion.identity) as GameObject;
enemy.GetComponent<enemyTwo>().setID(enemyTwoCounter);
enemyTwoCounter++;
}
}
if (Time.time <= 30.0f && Time.time >= 25.0f) {
if (Time.time > nextSpawn) {
nextSpawn = Time.time + 5.0f;
GameObject enemy = Instantiate(enemyTwo, new Vector3(0, 0, -1950f), Quaternion.identity) as GameObject;
enemy.GetComponent<enemyTwo>().setID(enemyTwoCounter);
enemyTwoCounter++;
GameObject enemya = Instantiate(enemyTwo, new Vector3(0, 0, -1950f), Quaternion.identity) as GameObject;
enemya.GetComponent<enemyTwo>().setID(enemyTwoCounter);
enemyTwoCounter++;
GameObject enemyb = Instantiate(enemyTwo, new Vector3(0, 0, -1950f), Quaternion.identity) as GameObject;
enemyb.GetComponent<enemyTwo>().setID(enemyTwoCounter);
enemyTwoCounter++;
}
}
if (Time.time <= 33.0f) {
if (Time.time > nextSpawn) {
nextSpawn = Time.time + 3.0f;
GameObject enemy = Instantiate(enemyThree, new Vector3(-1400f, 0, -2000f), Quaternion.identity) as GameObject;
enemy.GetComponent<enemyThree>().setID(enemyThreeCounter);
enemyThreeCounter++;
}
}
if (Time.time <= 36.0f && Time.time >= 33.0f) {
if (Time.time > nextSpawn) {
nextSpawn = Time.time + 3.0f;
GameObject enemy = Instantiate(enemyThree, new Vector3(1400f, 0, -2000f), Quaternion.identity) as GameObject;
enemy.GetComponent<enemyThree>().setID(enemyThreeCounter);
enemyThreeCounter++;
}
}
if (Time.time <= 39.0f && Time.time >= 36.0f) {
if (Time.time > nextSpawn) {
nextSpawn = Time.time + 3.0f;
GameObject enemy = Instantiate(enemyThree, new Vector3(0, 0, -2000f), Quaternion.identity) as GameObject;
enemy.GetComponent<enemyThree>().setID(enemyThreeCounter);
enemyThreeCounter++;
}
}
if (Time.time <= 45.0f && Time.time >= 39.0f) {
if (Time.time > nextSpawn) {
nextSpawn = Time.time + 6.0f;
GameObject enemy = Instantiate(enemyThree, new Vector3(-1400f, 0, -2000f), Quaternion.identity) as GameObject;
enemy.GetComponent<enemyThree>().setID(enemyThreeCounter);
enemyThreeCounter++;
GameObject enemya = Instantiate(enemyThree, new Vector3(1400f, 0, -2000f), Quaternion.identity) as GameObject;
enemya.GetComponent<enemyThree>().setID(enemyThreeCounter);
enemyThreeCounter++;
GameObject enemyb = Instantiate(enemyThree, new Vector3(0, 0, -2000f), Quaternion.identity) as GameObject;
enemyb.GetComponent<enemyThree>().setID(enemyThreeCounter);
enemyThreeCounter++;
}
}