首页 > 代码库 > Unity3d修炼之路:GUI按钮简单使用,完成对一个简单对象Cube的移动,旋转
Unity3d修炼之路:GUI按钮简单使用,完成对一个简单对象Cube的移动,旋转
#pragma strict private var m_pCubeObj : GameObject = null; private var m_pMeshFilter : MeshFilter = null; public var m_fTramslateSpeed : float = 20.0f; public var m_fRotateSpeed : float = 60.0f; function OnGUI(){ GUI.Label(new Rect(0.0f,0.0f,Screen.width,20.0f),"this is my first GUI"); if(GUI.Button(new Rect(5.0f,30.0,100.0f,40.0f),"Click me")) { m_pCubeObj = GameObject.CreatePrimitive(PrimitiveType.Cube);//创建一个Cube if(null != m_pCubeObj) { m_pCubeObj.transform.position = new Vector3(1.0f,2.0f,0.0f); } } if(GUI.Button(new Rect(5.0f,170.0f,100.0f,40.0f),"向前移动")) { m_pCubeObj.transform.Translate(Vector3.forward * Time.deltaTime * m_fTramslateSpeed); } if(GUI.Button(new Rect(115.0f,170.0f,100.0f,40.0f),"向后移动")) { m_pCubeObj.transform.Translate(Vector3.forward * Time.deltaTime * -m_fTramslateSpeed); } if(GUI.Button(new Rect(225.0f,170.0f,100.0f,40.0f),"向左移动")) { m_pCubeObj.transform.Translate(Vector3.left * Time.deltaTime * m_fTramslateSpeed); } if(GUI.Button(new Rect(335.0f,170.0f,100.0f,40.0f),"向右移动")) { m_pCubeObj.transform.Translate(Vector3.left * Time.deltaTime * -m_fTramslateSpeed);//Vector.right } if(GUI.Button(new Rect(5.0f,220.0f,100.0f,40.0f),"向左旋转")) { m_pCubeObj.transform.Rotate(Vector3.up * Time.deltaTime * -m_fRotateSpeed); } if(GUI.Button(new Rect(115.0f,220.0f,100.0f,40.0f),"向右旋转")) { m_pCubeObj.transform.Rotate(Vector3.up * Time.deltaTime * m_fRotateSpeed); } }
Unity3d修炼之路:GUI按钮简单使用,完成对一个简单对象Cube的移动,旋转
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。