#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); } }