- Home /
How to spawn more enemies once I've killed one?
I currently have a scene where there is one enemy and if i kill him, he goes away. I want to make it so when i kill the enemy, 2 more appear and so on. **I am new to unity so i need to know where to put the script and specific step by step procedure. Thx!
Answer by Slev · Sep 21, 2014 at 06:27 PM
The simple way would be to create a monitor script attached to an object in the level, or to the camera.
Then we can use FindGameObjectsWithTag to count them i.e.:
int enemy_count = 0;
foreach (GameObject g in GameObject.FindGameObjectsWithTag("enemy"))
enemy_count++;
for (int i = enemy_count; i < max_enemies; i++)
Instantiate("enemy");
What that does is count all your enemies, so we count 2 and max_enemies is 3, then we'll instantiate one new one. You could also use a function called by the OnDestroy() method of enemy.
where should i attach this script? and is max_enemies a variable?
Your answer
Follow this Question
Related Questions
Spawning enemy mobs .......... Instantiate woe ? 2 Answers
Error: Instantiated Enemies don't get hit 2 Answers
Spawner continuing after boss dies 1 Answer
Tower Defence style spawning(enemies) 1 Answer
Destroy and Spawn an Enemy 1 Answer