Destroy Multiple Objects with tag
Hi :)
I'm now trying to destroy multiples tagged object, however, it doesn't work. The code is below:
public GameObject TargetObj;
void Update()
{
var num_TargetObj = GameObject.FindGameObjectsWithTag("Target_Obj").Length;
if (Input.GetKeyDown("d"))
{
for (int i = 0; i <= 2; i++)
{
GameObject.Destroy(GameObject.Find("Plane_Target(Clone)"));
}
}
if (Input.GetKeyDown("g"))
{
GenerateObj();
}
}
public void GenerateObj()
{
var num_TargetObj = GameObject.FindGameObjectsWithTag("Target_Obj").Length;
if (num_TargetObj < 2)
{
Instantiate(TargetObj, new Vector3(2, 1, 1), Quaternion.identity);
Debug.Log("Generate right");
Instantiate(TargetObj, new Vector3(-2, 1, 1), Quaternion.identity);
Debug.Log("Generate left");
}
}
I checked some past conversation, however, they described the object should destroy once when the script found the tagged object. If I execute this script, it seems the script delete only one object for every frame (so I need to call destroy function for two frames if I want to delete two generated objects.
I'm quite new for unity, so probably I might missed something. Any advice will help me, thank you very much in advance.
Your answer

Follow this Question
Related Questions
How to i fix this animation error? 0 Answers
ANDROID APPLICATION PAUSED. UPDATE() DON'T WORKS BUT START() WORKS 1 Answer
building gradle project failure after importing google play service plugin 1 Answer
Empty package accepted to the asset store, 0 Answers
hello every body i using unity .5.5.2.f1 and i have thes error someone can help . thanks 0 Answers