Unity3D GUI学习
2015-11-06 10:53
381 查看
Unity3D内置有GUI,
首先,使用GUI实现一个按钮,并且点击实现触发,
这里屏幕上会创建一个按钮,点击按钮,会出现下面那句话:
![](http://images2015.cnblogs.com/blog/637344/201511/637344-20151106103708274-1924008053.jpg)
文本输入框的使用:
注意这里的赋值要赋值给自己,不然每一帧显示,会把前面的值刷掉的
![](http://images2015.cnblogs.com/blog/637344/201511/637344-20151106110120883-1685479715.jpg)
复选框:
可以实现,选择和取消的效果,每一次进行点击,都会刷新toogbaleT值来决定显示的效果:
![](http://images2015.cnblogs.com/blog/637344/201511/637344-20151106110953289-1551062060.jpg)
进度条的实现:
效果图:
首先,使用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"); } }
这里屏幕上会创建一个按钮,点击按钮,会出现下面那句话:
![](http://images2015.cnblogs.com/blog/637344/201511/637344-20151106103708274-1924008053.jpg)
文本输入框的使用:
注意这里的赋值要赋值给自己,不然每一帧显示,会把前面的值刷掉的
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); } }
![](http://images2015.cnblogs.com/blog/637344/201511/637344-20151106110120883-1685479715.jpg)
复选框:
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值来决定显示的效果:
![](http://images2015.cnblogs.com/blog/637344/201511/637344-20151106110953289-1551062060.jpg)
进度条的实现:
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); } }
效果图:
![](http://images2015.cnblogs.com/blog/637344/201511/637344-20151106112056977-58531245.jpg)
相关文章推荐
- 在Unity项目中使用Git
- Unity获取安卓电量和时间
- unity中的碰撞检测
- Unity与android交互错误集合
- 关于ShareSDK for Unity的分享界面修改
- Unity3d 屏幕空间人体皮肤知觉渲染&次表面散射Screen-Space Perceptual Rendering & Subsurface Scattering of Human Skin
- [置顶] Unity3d 屏幕空间人体皮肤知觉渲染&次表面散射Screen-Space Perceptual Rendering & Subsurface Scattering of Human Skin
- 【Unity】使用Time.timeScale暂停游戏的时候的一些问题
- 【Unity】 DoTween对UI进行DoFade操作存在问题
- Unity游戏开发使用Assetbundle加载场景的实战
- Unity游戏开发使用Assetbundle加载场景的原理
- unity3d-地图制作之暗光
- Unity3d通用工具类之定时触发器
- Unity3d通用工具类之定时触发器
- unity3D内的常用输入对象
- unity手游之聊天SDK集成与使用一
- Unity3D学习笔记
- 用unity surface shader 重新渲染dota2 模型
- Unity 角色释放技能后使周围物体具有爆炸效果
- unity调用别的脚本里面的方法