Clearing the screen of Enemies


After 60 seconds I want all the Enemies on the screen.
Here are the routines:

Can anyone help explain why this is not working?


Here you can see that they are tagged correctly:


Are you receiving any compile or runtime errors or are the enemies just not disappearing?

Destroy (GameObject.FindWithTag("Enemies"));

If i am right the way you are doing it is its looking for a gameobject called Enemies not its tag which it wont find.


I would concur…


Does this script find all enemies or just one? I cant try it right now. Perhaps you would have to use it with foreach as well, but I don`t know.

I think that you should use something like:

GameObject enemy = GameObject.FindGameObjectsWithTag(“Enemies”);
foreach(GameObject x in enemy)


Yep, you will need to find all objects with that tag.
FindGameObjectsWithTag will return an array of type GameObjects as far as im aware;

        GameObject [] foundEnemies = GameObject.FindGameObjectsWithTag("Enemies");
	Debug.Log("Number of enemies found : " + foundEnemies.Length);

	if(foundEnemies.Length != 0)
		foreach( GameObject enemy in foundEnemies)

so adding that would create an array, then allocate all enemies found with that tag,
and as Joao said, a ForEach to iterate through it and mark each game object element to be destroyed at the end of the frame.


Nice one @OboShape, Awesome! :+1:


Thanks for the help. Here is what I have learned

What the code does is search for something called “Enemies” in the hierarchy and destroy it, and all its children.
So if I could instantiate all my enemies under “Enemies” I would have my solution.


If i remember rightly again zombie runner covers instantiating objects as a child of an empty gameobject which in your case you name Enemies.


Hey @RetroDan - glad to hear you’ve got it sorted… could you mark the post as solved - thanks in advance :slight_smile: