public class CUtils
{
/// <summary>
/// find child by name
/// </summary>
/// <param name="transform"></param>
/// <param name="name"></param>
/// <returns></returns>
public static Transform GetChild(Transform transform, string name)
{
Transform final = null;
if (transform.Find(name) != null)
{
final = transform.Find(name);
return final;
}
else
{
for (int i = 0; i < transform.childCount; i++)
{
if (transform.GetChild(i).childCount != 0)
{
final = GetChild(transform.GetChild(i), name);
if (final != null)
break;
}
}
}
return final;
}
}
![](https://img2024.cnblogs.com/blog/35695/202408/35695-20240826070647288-243310440.jpg)