C#静态类寻找被隐藏的Transforms的物体

tech2024-06-24  162

using System.Collections; using System.Collections.Generic; using UnityEngine; using System; /* Class:寻找当前对象下所有的物体(静态类) Author:pqy */ namespace Assets.Scripts.GameTools { static class GameTools { private static Transform target = null; public static Transform FindChild(Transform origin, string name) { for (int i = 0; i < origin.childCount; i++) { Transform trans = origin.GetChild(i); if (trans.name == name) { return trans; } else { Transform tmp = FindChild(trans, name); if (tmp != null) { return tmp; } } } return null; } } }

直接使用GameTools.FindChild即可。 

 

最新回复(0)