public GameObject OnNode; 首先将变量加入到节点中 反射机制
OnNode.SendMessage("DoRoate"); 向节点中发送消息,执行DoRoate函数 注意函数名调用
void DoRoate() 函数执行
{
Debug.Log("接收到消息!");
rotateSpeed = 180f;
}
游戏物品GameObject ——节点
GameObject node = GameObject.find("物体名称")通过名称 可以找到物体 可以调用节点中的内容
GameObject node = GameObject.find("父节点名称/子节点名称")可以通过路径找到
GameObject node = GameObject.Find("控制机翼旋转"); 找到节点
Revolve audio = node.GetComponent<Revolve>(); 调用节点中的Revolve变量 audio.DoRoate(); 调用变量中的函数
public GameObject rad1Node; 将节点放入
Revolve audio = rad1Node.GetComponent<Revolve>(); 再调用Revolve
audio.DoRoate(); 再调用DoRoate函数
Transform parent = this.transform.parent; 获取父结点的transform
GameObject nodeParent = this.transform.parent.gameObject; 获取父结点的gameObject
foreach (Transform Child in transform) 找到父节点下所有子节点
{ Child.name = Child.gameObject.name 已经对Child.gameObject.name 进行了封装
Debug.Log("子节点名称:" + Child.name);
}
Transform Child1 = this.transform.GetChild(0); 找到父节点下第一个子节点的transform
Debug.Log("子节点名称:" + Child1.name);
Transform Child2 = this.transform.Find("控制机翼旋转"); 通过Find找一级子节点
if (Child2 != null)
{
Debug.Log("子节点名称:" + Child2.name);
}
else
{
Debug.Log("未找到子节点");
}
Transform Child3 = this.transform.Find("控制机翼旋转/旋翼"); 通过路径查找子节点
Transform name1 = this.transform.Find("/小车和鼠标位置"); 找到节点
this.transform.SetParent(name1); 将this放到节点下
this.transform.SetParent(null); 将this放到一级节点
Child1.gameObject.activeSelf 判断物品当前状态打开还是关闭
Child1.gameObject.SetActive(false/true); 将物品显示关闭/显示打开
int num = this.transform.childCount; 节点中一级子节点的个数
更多推荐
4.Unity中c#代码学习(消息发布+物体获取+父子结点获取创建)
发布评论