public static GameObject FindObjectWithLayer(GameObject rootObj, int nFindLayer) { if (rootObj == null) { return(null); } if (rootObj.get_layer() == nFindLayer) { return(rootObj); } for (int i = 0; i < rootObj.get_transform().get_childCount(); i++) { GameObject gameObject = NgObject.FindObjectWithLayer(rootObj.get_transform().GetChild(i).get_gameObject(), nFindLayer); if (gameObject != null) { return(gameObject); } } return(null); }
public static GameObject FindObjectWithLayer(GameObject rootObj, int nFindLayer) { if (rootObj == null) { return(null); } if (rootObj.layer == nFindLayer) { return(rootObj); } for (int i = 0; i < rootObj.transform.childCount; i++) { GameObject gameObject = NgObject.FindObjectWithLayer(rootObj.transform.GetChild(i).gameObject, nFindLayer); if (gameObject != null) { return(gameObject); } } return(null); }