would do it. But debugger console says smth. like "can't destoy transform component, because other components depend on it".
I have like 100 objects that need/can be destoyed, I wouldn't want to tag them or name them one by one with unique names. Or maybe I should all rename them to name + number and have some array?
Please help, I have no idea how to do this. Please reply with code I can use.
Another option would be to store references to the objects so you can destroy them without the Find call. Something like this:
var children : GameObject[]; // Use the inspector to populate the array.
function DestroyOne(var i : int){
Destroy(children*);*
*}*
*function DestroyAll(){*
*for(var child in children)*
*Destroy(child);*
*}*
*```*
*<p>If the number of child objects makes assigning them via the inspector unwieldy, try assigning them at runtime by calling Find up front and populating an array or Hashtable with the results. That way you can avoid calling Find when destroying the objects.</p>*
*<p>Even better, maybe there's a way to just deactivate the objects and reuse them instead of destroying them. Not sure if this makes sense in your particular situation or not.</p>*
*```*
*child.active = false;*
*// or, to deactivate the child's children as well:*
*child.SetActiveRecursively(false);*
*```*
*<p>What kind of event is triggering the destruction of the child objects? It's possible you don't need to use Find or a cached array at all.</p>*