If all tagged objects are destroyed

This script should respawn Objects with the Tag Target1 but instead of respawning when their all destroyed they just duplicate immediently an when I destroy all they don’t respawn.
pease help thx :smiley:

 void Start()
 {
 if (respawns == null)
     respawns = GameObject.FindGameObjectsWithTag("Target1");
 foreach (GameObject respawn in respawns)
 {
     Instantiate(respawnPrefab, respawn.transform.position, respawn.transform.rotation);
 }
}

Hello.

Then you need first, detect when are all destroyed, and then, need to instantiate the prefabs in the positions. The “problem” is that the positions can not be obtained form the objects, because they are destroyed.

So First, you need to do something to know the positions without need the objects. (you can sotre its Vector3 position on destroy, or have emptyobjects at the respawn points…)

To detect if they are all destroyed, you need to remake the array of “respawn” objects every time, and when its lenght is 0 means all are destroyed

respawns = GameObject.FindGameObjectsWithTag("Target1");
if (respawns.Length = 0)
{
Spawn them all
}

And as I said, you need something to know the positions where the objects was before beeing destroyed. I’m sure you will find a way!!

Bye!