Destroy GameObjectsWithTag in Game

I have multiple gameobjects in my scene and they all have the same tag. How can I kill them all?

I thought that this might be a solutuion but GameOBject.FindWithTag() does not contain a defintion for GetEnumerator! :(

foreach (GameObject go in GameObject.FindWithTag("MyObject")) Destroy(go.gameObject, 0.5f);

1 Answer

1
var stuff : GameObject[] = GameObject.FindGameObjectsWithTag("MyObject");

for(item in stuff)
{
    Destroy(item);
}

thanks so very much, do you need help with anything?

The "private var item : Transform" line isn't doing anything, since the "item" variable in "for (item in stuff)" doesn't exist outside that loop.

That's true - fixed it.