码迷,mamicode.com
首页 > 编程语言 > 详细

Unity3D GUI学习

时间:2015-11-06 12:32:46      阅读:239      评论:0      收藏:0      [点我收藏+]

标签:

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

	}
	
}

  效果图:

技术分享

 

Unity3D GUI学习

标签:

原文地址:http://www.cnblogs.com/sunxun/p/4941957.html

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