zoukankan      html  css  js  c++  java
  • Unity3d修炼之路:GUIbutton简单使用,完毕对一个简单对象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);
    	}
    	
    	
    }

  • 相关阅读:
    WINCE串口打印信息的屏蔽与打开
    WINCE系统时间设置
    WINCE调试常见错误
    今天开始研究arcgisserver
    今天开始,放弃项目管理,做技术了
    java数据库连接
    [转]建一个XMLHttpRequest对象池
    Linux下jsp开发环境,apache,tomcat服务器配置过程
    div+css布局漫谈
    新图纸总结
  • 原文地址:https://www.cnblogs.com/liguangsunls/p/7346259.html
Copyright © 2011-2022 走看看