unity destroy all children

Code Example - unity destroy all children

                
                        while (transform.childCount > 0) {
    DestroyImmediate(transform.GetChild(0).gameObject);
}
                    
                
 

unity delete all children

                        
                                foreach (Transform child in transform) {
     Destroy(child.gameObject);
 }
                            
                        
 

Related code examples