Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

unity find object by name

    public GameObject FindChildRecursive(GameObject parent, string childName) {
        foreach(Transform child in parent.transform) {
            if(child.name == childName) {
                return child.gameObject;
            } else {
                if(child.childCount > 0) {
                    GameObject result = FindChildRecursive(child.gameObject, childName);
                    if(result != null) return result;
                }
            }
        }
        return null;
    }
 
PREVIOUS NEXT
Tagged: #unity #find #object
ADD COMMENT
Topic
Name
1+7 =