Last Updated: February 25, 2016
·
978
· badawe

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;
    }