Answers for "how to destroy all children"

0

how to destroy all children

public void ClearChildren() {
    Debug.Log(transform.childCount);
    float i = 0;
    foreach (Transform child in transform) {
        i += 1;
        DestroyImmediate(child.gameObject);
    }
    Debug.Log(transform.childCount);
}
Posted by: Guest on March-16-2021
0

how to destroy all children

while (transform.childCount > 0) {
    DestroyImmediate(transform.GetChild(0).gameObject);
}
Posted by: Guest on March-16-2021

Browse Popular Code Answers by Language