Unity3D如何获取对象和子对象
在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如何获取对象和子对象的全部內容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: Angular Component 的
- 下一篇: Angular应用页面里_ngconte
