I need to delete an array of gameObjects
Is there a way to do that?
Array.Clear doesn’t seem to work. ![]()
GameObject[] boxes;
boxes = GameObject.FindGameObjectsWithTag("Box");
Array.Clear(boxes, 0, boxes.Length);
I need to delete an array of gameObjects
Array.Clear doesn’t seem to work. ![]()
GameObject[] boxes;
boxes = GameObject.FindGameObjectsWithTag("Box");
Array.Clear(boxes, 0, boxes.Length);
Array.Clear does not actually destroy/delete the GameObjects, it just removes the reference from the array. To delete the GameObject, you should use Destroy.
GameObject [] boxes = GameObject.FindGameObjectsWithTag("Box");
for (int i = boxes.Length - 1; i >= 0; i--) {
Destroy (boxes[i]);
}
Why do you think it isn't working?
– ArachnidAnimal