Hi,
I’m using the following editor script:
@CustomEditor (CubeLine)
class CubeLineEditor extends Editor {
function OnInspectorGUI () {
if (GUI.changed)
EditorUtility.SetDirty (target);
if(GUILayout.Button ("Generate Boxes")) {
target.GenerateCubes();
}
if(GUILayout.Button ("Destroy Boxes")) {
target.KillChildren();
}
DrawDefaultInspector();
}
}
Referencing the KillChildren() function on another script:
function KillChildren () {
for(var child : Transform in transform){
DestroyImmediate(child.gameObject);
}
}
So I have a button which when pushed instantiates a load of cubes, and a button which is supposed to destroy them all. However, the destroy button takes a few presses to actually destroy all the instantiated clones.
When it’s 10 boxes to destroy, it takes four clicks.
When 30, five clicks.
When 100, seven clicks. And so on.
Why doesn’t the code successfully loop through all the children and destroy them all in one click/one run of the function?
Thanks
S