Hi,
I’d just like to know if there’s some quick way of destroying every GameObject in an array of them. I tried Destroy(array), but Unity didn’t like it. I could destroy each one individually using a loop or something, but I think there must be an easier way of doing it than that…
Very thank you, and merry unitying!
You can do a loop in a couple different ways. for or foreach will work.
if(Inventory.Length > 0)
{
foreach(GameObject go in Inventory)
{
Destroy(go);
}
}
//OR
for(int i = 0; i < Inventory.Length; i++)
{
Destroy(Inventory*.gameObject);*
}
Sorry if this is wrong , but I think you can do this by using a For loop , the code below is in Javascript and uses an array called “Inventory”.
for (var i = 0; i < Inventory.Length; i++) {
Destroy(Inventory*);*
}
Here it is:
while (Inventory.Length > 0) {
Destroy(Inventory[0]);
}