/// <summary>
/// Extension method for UnityEngine.Transform.
/// Finds the children with tag.
/// Returns an array.
/// </summary>
/// <returns>The children with tag.</returns>
/// <param name="tag">Tag.</param>
public static Transform[] FindChildrenWithTag(this Transform trans, string tag)
{
Transform[] kids = trans.GetComponentsInChildren<Transform> ();
Transform[] kidsWithTag = new Transform[] {};
foreach (Transform kid in kids)
{
if (kid.tag == tag)
{
kidsWithTag [kidsWithTag.Length] = kid;
}
}
return kidsWithTag;
}
Created
February 7, 2016 23:29
-
-
Save Ashwinning/551ab77201e89a352bff to your computer and use it in GitHub Desktop.
FindChildrenWithTag : An extension method that finds all children of a Transform with a specified tag, and returns an array. transform.FindChildrenWithTag("SpecifiedTag")
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment