首页 > 其他 > 详细

Unity3D如何获取对象和子对象

时间:2014-03-17 23:31:23      阅读:909      评论:0      收藏:0      [点我收藏+]
在Unity3d中获取游戏对象有三种方法:

一:获取对象

1.通过对象名称获取:objCube=GameObject.Find("Cube"); 

private var objCube:GameObject;
private var isCubeRoate=false;

function Start () {
  objCube=GameObject.Find("Cube");
}

function Update(){
  if(isCubeRoate){
     objCube.transform.Rotate(0.0f,Time.deltaTime*200,0.0f);
  }
}

function OnGUI(){
  if(GUILayout.Button("旋转",GUILayout.Height(50))){
     isCubeRoate=true;
  }
}

2.通过tag标签获取单个游戏对象:objCube=GameObject.FindWithTag("Finish");

3.通过游戏标签获取多组游戏对象:objCube=GameObject.FindGameObjectsWithTag("Finish");

 

二:子对象

//获取所有子对象
foreach (Transform child in transform)
{
    Debug.Log(child.gameObject.name);
}
  
 //销毁所有子对象
foreach(Transform child in transform){
    Destroy(child.gameObject);
}

Unity3D如何获取对象和子对象,布布扣,bubuko.com

Unity3D如何获取对象和子对象

原文:http://www.cnblogs.com/tonge/p/3605624.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!