You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

30 lines
974 B

using UnityEngine;
public static class Utils {
public static GameObject FindRecursive(this GameObject go, string child) {
var foundChild = go.transform.Find(child);
if (foundChild != null) {
return foundChild.gameObject;
}else {
var found = false;
GameObject newChild = null;
foreach (Transform newGo in go.transform) {
if (newGo.childCount > 0)
newChild = newGo.gameObject.FindRecursive(child);
found = child == newChild?.name;
if (found)
break;
}
if (found)
return newChild;
else
return null;
}
}
public static Transform FindRecursive(this Transform transform, string child) {
var foundChild = transform.gameObject.FindRecursive(child);
return foundChild != null ? foundChild.transform : null;
}
}