脚本获取场景中游戏体

来源:互联网 发布:黄耀明和林夕 知乎 编辑:程序博客网 时间:2024/06/05 16:28


方法一:通过游戏体的名字查找:
例如:
    GameObject plane= GameObject.Find ("Plane");   //获取场景中的Pane平面

    GameObject btnObj1 = GameObject.Find ("Canvas/angle0");    
    Button btn1 = (Button) btnObj1.GetComponent<Button>();    //获取Canvas下的button
       

方法二:通过tag标签查找:
例如:
     GameObject sphere=GameObject.FindGameObjectWithTag("mSphere");

     

方法三:设置公有成员变量,在U3D中拖进去。

注:脚本获取游戏体组件,通过GetComponent<组建类型>()方法获取即可:
例如:  this.GetComponent<Renderer> ().material.color = Color.red;



0 0