- Home /
Question by
Justin Warner · Nov 29, 2010 at 02:44 AM ·
destroygameobjects
Find gameobjects by tag, and destroy if in the distance of a certain game object...
var Enemy = GameObject.FindWithTag("Test");
Kill() {
Destroy(Enemy);
}
It'll only kill a couple of the enemies...
Hey, so I have this script, that gets the distance between 2 gameobjects, and if they distance is below a certain amount, it'll destroy the game object with the tag of Enemy, but the problem is, I have about 10 of these, all with the same tags, and the way I'm doing it isn't working, it only destroys one of the game objects, rather than all of them.
The reasoning why it does this is obvious, but I don't know how to fix it...
Comment
Best Answer
Answer by Uriel_96 · Nov 29, 2010 at 03:10 AM
put the
var Enemy = GameObject.FindWithTag("Test");
on the funtion Update(){} because if you do it like that its going to be searching for the enemy.