标签:add set ati one transform sea static orm name
1.加上命名空间,一个类在每个脚本都会实例化
2.递归调用懂了
//查找物体
public static Transform FindTheChild(GameObject goParent, string childName)
{
Transform searchTrans = goParent.transform.Find(childName);
if (searchTrans == null)
{
foreach (Transform trans in goParent.transform)
{
searchTrans = FindTheChild(trans.gameObject, childName);
if (searchTrans != null)
{
return searchTrans;
}
}
}
return searchTrans;
}
3.return searchTrans.gameObject.AddComponent<T>(); 返回T
4.递归调用设置Layer
//设置所以子物体的layer;
public static void SetLayer(int parentLayer, Transform childTrs)
{
childTrs.gameObject.layer = parentLayer;
for (int i = 0; i < childTrs.childCount; i++)
{
Transform child = childTrs.GetChild(i);
child.gameObject.layer = parentLayer;
SetLayer(parentLayer, child);
}
}
5.碰撞体可以频弊按钮
标签:add set ati one transform sea static orm name
原文地址:https://www.cnblogs.com/xiaomao21/p/9157784.html