码迷,mamicode.com
首页 > 移动开发 > 详细

Unity3d修炼之路:GUI按钮简单使用,完成对一个简单对象Cube的移动,旋转

时间:2014-11-17 22:56:12      阅读:355      评论:0      收藏:0      [点我收藏+]

标签:io   ar   os   使用   sp   java   for   on   cti   

#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的移动,旋转

标签:io   ar   os   使用   sp   java   for   on   cti   

原文地址:http://blog.csdn.net/xiaxiang123/article/details/41217909

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!