When game is over, I want to destroy all clones.
But just destroy one of all clones.
No destroy all clones.
I write like this:
if (gameover==true) {
Destroy(GameObject.FindWithTag("clone"));
}
There are clones and tag name are also call “clone”.
How can I do? Thanks!
FindWithTag returns only one object. You must use FindGameObjectsWithTag: it returns an array of objects with the specified tag - just sweep this array and destroy each element, like this:
if (gameover){ // you don't need to compare a boolean variable to true
var clones = GameObject.FindGameObjectsWithTag ("clone");
for (var clone in clones){
Destroy(clone);
}
}
Hi,
I am using this script you wrote for some time, but unless there is something wrong in my script, I think that there is an issue.
This removes all the taged objects except one. how can i remove ALL ?
Tnx,
Amit
Eldho
4
in C# its
var clones = GameObject.FindGameObjectsWithTag (“clone”);
foreach (var clone in clones){
Destroy(clone);
}