vmz0pa
Last Updated: February 25, 2016
·
243
· badawe
0 ourblbzsuef fgw4ymiklzdbuo8afoo4ywxhlqebpuno4sjztehuwnowcfhakjiq07 wopztnxhg

Find component upwards

Here is a extension to find one component upwards, is usefull when you have a lot of prefabs and need some dynamic linkage hierarchy

public static T FindComponentUpwards<T>(this Transform pTarget) where T : Component
    {
        Transform tTransform = pTarget.parent;
        while (true)
        {
            T tComponent = tTransform.GetComponent<T>();
            if (tComponent == null)
            {
                if (tTransform.parent)
                {
                    Transform tParentTransform = tTransform.parent;
                    tTransform = tParentTransform;
                    continue;
                }
                break;
            }
            return tComponent;
        }
        return null;
    }
Say Thanks
Respond