Advertisement
MaximilianPs

Unity - Search for Children v1.0

Nov 8th, 2020 (edited)
1,888
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.63 KB | None | 0 0
  1. /// <summary>
  2. /// Search each child of a GameObject searching for a string-name
  3. /// </summary>
  4. /// <param name="root">Parent gameObejct</param>
  5. /// <param name="aName">The name that you are looking for</param>
  6. /// <returns>The GameObject that you were looking for</returns>
  7. public static GameObject FindChild(GameObject root, string aName)
  8. {
  9.         SkinnedMeshRenderer[] children = root.GetComponentsInChildren<SkinnedMeshRenderer>(true);
  10.  
  11.         for (int i = 0; i < children.Length; i++)
  12.         {
  13.             if (children[i].name == aName)
  14.                 return children[i].gameObject;
  15.         }
  16.  
  17.         return null;
  18. }
  19.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement