使用Unity时怎样深度查找某个子物体和遍历所有子物体

2025-02-27 01:13:18
推荐回答(1个)
回答1:

///

/// 查找子节点 /// public static Transform FindDeepChild(GameObject _target, string _childName) { Transform resultTrs = null; resultTrs = _target.transform.Find(_childName); if (resultTrs == null) { foreach (Transform trs in _target.transform) { resultTrs = Utility.FindDeepChild(trs.gameObject, _childName); if (resultTrs != null) return resultTrs; } } return resultTrs; }

使用递归方法