- Home /
Destroy all Objects of a Type in Game
Hi, i want to destroy all Prefabs of a certain type ingame,
"JumpGemPrefab" is the name of the prefab, "JumpGemPrefab(Clone)" is the name ingame, and "JumpGem" is the name of the attached script.
enter code here
GameObject other = GameObject.Find("JumpGemPrefab(Clone)");
Destroy(other);
works but destroys only one of the Prefabs.
enter code here
GameObject[] others = (GameObject[])FindObjectsOfTypeAll(typeof(JumpGem));
foreach (GameObject other in others)
{ Destroy(other); }
has no effect.
Greetings Marcurion
Answer by Marcurion · Dec 12, 2011 at 08:29 AM
Thanks guys, Dakwamine's script with other.gameObject works perfectly.
Greetings Marcurion
Then please "accept" my script's answer to make it green. ^^ It is a kind of round validation button on the left of the answer. Oh, and one last advice : if you want to thank someone for his answer or answer to his "answer", please use the "add new comment" little button ins$$anonymous$$d of the answer box below. This "answers" site works differently from a forum. ^^