zoukankan      html  css  js  c++  java
  • Unity3D GUI学习

    Unity3D内置有GUI,

    首先,使用GUI实现一个按钮,并且点击实现触发,

    	void OnGUI()
    	{
    		//GUI.Button (new Rect (10,10,50,50), "nihaoa ");
    		if(GUI.Button(new Rect (50, 50, 50, 50),"Button"))
    			
    		{
    			Debug.Log("wo shi yi ge an niu");
    			
    		}
    
    	}
    

     这里屏幕上会创建一个按钮,点击按钮,会出现下面那句话:

    文本输入框的使用:

    注意这里的赋值要赋值给自己,不然每一帧显示,会把前面的值刷掉的

    using UnityEngine;
    using System.Collections;
    
    public class getbutton : MonoBehaviour {
    
    	// Use this for initialization
    
    	public Rect rec;
        public string text;
    	void Start () {
           text  =  "请输入";
    	}
    	
    	// Update is called once per frame
    	void Update () {
    
    
    	}
    
    	void OnGUI()
    	{
           
           text =  GUI.TextField(new Rect(0, 0, 100, 100), text);
    
    	}
    	
    }
    

      

    复选框:

    using UnityEngine;
    using System.Collections;
    
    public class getbutton : MonoBehaviour {
    
    	// Use this for initialization
    
    
        public bool toogbaleT = true;
        public bool toogbaleM = false;
    	void Start () {
         
    	}
    	
    	// Update is called once per frame
    	void Update () {
    
    
    	}
    
    	void OnGUI()
    	{
    
    
            toogbaleT = GUI.Toggle(new Rect(0, 0, 50, 50), toogbaleT, "体育");
            toogbaleM = GUI.Toggle(new Rect(55, 55, 50, 50), toogbaleM, "美术");
    
    	}
    	
    }
    

    可以实现,选择和取消的效果,每一次进行点击,都会刷新toogbaleT值来决定显示的效果:

    进度条的实现:

    using UnityEngine;
    using System.Collections;
    
    public class getbutton : MonoBehaviour {
    
    	// Use this for initialization
    
        public float hsliaervalue = 0f;
    
    	void Start () {
         
    	}
    	
    	// Update is called once per frame
    	void Update () {
    
    
    	}
    
    	void OnGUI()
    	{
    
            hsliaervalue = GUI.HorizontalSlider(new Rect(140, 210, 100, 30), hsliaervalue, 0, 10);
    
    	}
    	
    }
    

      效果图:

  • 相关阅读:
    C++字符串转数字,数字转字符串
    [转]基础知识整理
    POJ 3071 Football
    POJ 3744 Scout YYF I
    2013成都Regional:一块木板,几个气球
    HDOJ 4497 GCD and LCM
    POJ 1185 炮兵阵地
    POJ 2031 Building a Space Station
    HDOJ 4717 The Moving Points
    CSU 1328: 近似回文词
  • 原文地址:https://www.cnblogs.com/sunxun/p/4941957.html
Copyright © 2011-2022 走看看