为了方便组件的寻找,可以使用脚本遍历搜索的方法,获取需要使用的目标组件、gameObject。
public static Transform DeepFind(this Transform parent , string targetName)
{
foreach (Transform child in parent)
{
//Debug.Log(child.name);
if (child.name == targetName)
{
return child;
}
else if (DeepFind(child, targetName))
{
return DeepFind(child, targetName);
}
}
return null;
}
使用
transform.DeepFind("WeaponHandleR")
this关键字在静态方法中的使用
this关键字不能在静态方法的方法体(即大括号之间的部分)中使用、但是可以在参数中使用(即C#的扩展方法)。
扩展方法的第一个参数指定方法所操作的类型;该参数必须以 this 修饰符开头。