Last active
June 5, 2019 21:59
-
-
Save fidelsoto/ae8fd0240384a04f0696ec0e26bb0d12 to your computer and use it in GitHub Desktop.
Class contains an extension method for the transform class that adds a Clear function to clear a transform's children. In this code we can see the usage of extension methods and comments.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Extension method for the Transform class, Destroys all of its children starting at a given index (optional, default 0). | |
/// </summary> | |
/// <param name="container">The transform containing the child objects.</param> | |
/// <param name="startIndex">The index at which we should begin destroying the objects.</param> | |
public static void Clear(this Transform container, int startIndex = 0) | |
{ | |
for (int i = startIndex; i < container.childCount; i++) | |
{ | |
Destroy(container.GetChild(i).gameObject); //Use ObjectPool.Destroy to use with pooling system. | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment