Search for a Gameobject by name, inside a Transform hierarchy
Usage
Transform tTrans = anotherTransform.Search("desiredName");
Extension
public static Transform Search(this Transform target, string name)
{
if (target.name == name) return target;
for (int i = 0; i < target.childCount; ++i)
{
var result = Search(target.GetChild(i), name);
if (result != null) return result;
}
return null;
}
Written by Bruno Mikoski
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Unity
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#