SecretAnorak

TransformDeepChildExtension

Apr 26th, 2019
1,027
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.45 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4.  public static class TransformDeepChildExtension
  5.  {
  6.      //Breadth-first search
  7.      public static Transform FindDeepChild(this Transform aParent, string aName)
  8.      {
  9.          var result = aParent.Find(aName);
  10.          if (result != null)
  11.              return result;
  12.          foreach(Transform child in aParent)
  13.          {
  14.              result = child.FindDeepChild(aName);
  15.              if (result != null)
  16.                  return result;
  17.          }
  18.          return null;
  19.      }
  20.  }
Advertisement
Add Comment
Please, Sign In to add comment