Created
October 6, 2020 20:24
-
-
Save leventeren/edfe6810f61323d0acfaa2e000ee0e7b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static GameObject FindChild(Transform trans , string childName) | |
{ | |
Transform child = trans.Find(childName); | |
if (child != null) | |
{ | |
return child.gameObject; | |
} | |
int count = trans.childCount; | |
GameObject go = null; | |
for(int i = 0 ; i < count ; ++i) | |
{ | |
child = trans.GetChild(i); | |
go = FindChild(child, childName); | |
if (go != null) | |
return go; | |
} | |
return null; | |
} | |
public static T FindChild<T>(Transform trans, string childName) where T : Component | |
{ | |
GameObject go = FindChild(trans,childName); | |
if(go == null) | |
return null; | |
return go.GetComponent<T>(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment