public static Transform GetAncestor(Transform transform, int minChildCount) { if (transform == null) { return(null); } if (!(transform.parent != null)) { return(null); } if (transform.parent.childCount >= minChildCount) { return(transform.parent); } return(Hierarchy.GetAncestor(transform.parent, minChildCount)); }