Skip to content

Instantly share code, notes, and snippets.

@litvil
Created February 12, 2015 13:21
Show Gist options
  • Save litvil/2abf6e289db9e7e9270d to your computer and use it in GitHub Desktop.
Save litvil/2abf6e289db9e7e9270d to your computer and use it in GitHub Desktop.
int childs = transform.childCount;
for (int i = childs - 1; i > 0; i--)
{
GameObject.Destroy(transform.GetChild(i).gameObject);
}
@Ilyvin
Copy link

Ilyvin commented Jul 9, 2019

your code has bug.
this is better:

for (int i = 0; i < transform.childCount; i++)
{
GameObject.Destroy(transform.GetChild(i).gameObject);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment