Esempio n. 1
0
    public static GameObject FindSecurely(GameObject self, string name, [Optional, DefaultParameterValue(true)] bool recursive)
    {
        GameObject gameObject = null;
        Transform  transform  = self.transform;
        int        childCount = transform.childCount;

        for (int i = 0; i < childCount; i++)
        {
            Transform child = transform.GetChild(i);
            if (child.gameObject.name == name)
            {
                gameObject = child.gameObject;
                break;
            }
            if (recursive)
            {
                Transform transform3 = TransformExtensions.FindChildRecursively(child, name);
                if (transform3 != null)
                {
                    gameObject = transform3.gameObject;
                    break;
                }
            }
        }
        if (gameObject == null)
        {
            Debug.LogError("GameObject `" + name + "' not found!");
        }
        return(gameObject);
    }