Destroy all Children in Unity
How to destroy all children of a gameobject
Jul 15, 2021
We finally added some thrusters to our enemies, but when they get destroyed the play an animation. This prevents us from destroying the game object for visual reasons, until the animation is finished. The thrusters are childs of the enemy game object. When we start of enemy death sequence we use the following code to destroy all children:
foreach(Transform child in this.transform)
{
Destroy(child.gameObject);
}
There are many ways to do this, but this seems to be the cleanest and simplest way without much code.