- Home /
Question by
KloverGames · Jul 18, 2019 at 02:18 AM ·
gameobjectinstantiateprefabdestroyhierarchy
How to destroy all gameobjects active in hierarchy?
So I just want to know how to destroy not the prefab but all of the gameobjects of that prefab in the hierarchy, it's like when the player collides with a meteor all of the meteors active in the hierarchy need to be destroyed if the player wants to try again.
Comment
Best Answer
Answer by jintaenate · Jul 18, 2019 at 04:25 AM
Easy way to destroy all specific prefab in scene is to use tag.
You should add specific tag for your prefab and find tag.
void DestroyPrefabsInScene(string tagName) {
GameObject[] prefabs = GameObject.FindGameObjectsWithTag(tagName);
foreach (GameObject prefab in prefabs)
{
Destroy(prefab);
}
}