Unity3D 基础篇--button入门
2016-03-11 18:41
531 查看
Button是Unity3D中GUI系统的常用控件,其函数原型如下:
参数说明:
position : Rect ——屏幕上的矩形位置(x坐标,y坐标,宽度,高度)。
text : String ——显示的文本内容。
image : Texture ——显示的纹理(图片)。
content : GUIContent ——在标签上显示的文本、图片和信息提示。
style : GUIStyle ——使用的样式,如果不使用,那么标签的样式使用的就是当前的GUISkin皮肤
按钮共有三个基本状态组成:未点击状态、击中状态、点击后状态。一般情况下,游戏界面的按钮只监听“未点击状态”与“点击后状态”两种。
按钮展现方式分为两种:“普通按钮”和“图片按钮”。普通按钮为系统默认显示的按钮,而图片按钮可以设定按钮的背景图案。
下面以实际简单的代码为例:
staticfunction Button(position: Rect, text: string):bool; staticfunction Button(position: Rect, image: Texture): bool; staticfunction Button(position: Rect, content: GUIContent): bool; staticfunction Button(position: Rect, text: string, style: GUIStyle): bool; staticfunction Button(position: Rect, image: Texture, style: GUIStyle): bool; staticfunction Button(position: Rect, content: GUIContent, style: GUIStyle): bool;
参数说明:
position : Rect ——屏幕上的矩形位置(x坐标,y坐标,宽度,高度)。
text : String ——显示的文本内容。
image : Texture ——显示的纹理(图片)。
content : GUIContent ——在标签上显示的文本、图片和信息提示。
style : GUIStyle ——使用的样式,如果不使用,那么标签的样式使用的就是当前的GUISkin皮肤
按钮共有三个基本状态组成:未点击状态、击中状态、点击后状态。一般情况下,游戏界面的按钮只监听“未点击状态”与“点击后状态”两种。
按钮展现方式分为两种:“普通按钮”和“图片按钮”。普通按钮为系统默认显示的按钮,而图片按钮可以设定按钮的背景图案。
下面以实际简单的代码为例:
publicclassButtons : MonoBehaviour { publicTexture buttonTexture; privatestringinfo = ""; voidStart () { } //Update is called once per frame voidUpdate () { } voidOnGUI() { // 文本显示 GUI.Label (newRect (50, 200, 200, 50), info); // 第一个文字按钮 GUI.color = Color.yellow; //按钮文字颜色 GUI.backgroundColor = Color.red; //按钮背景颜色 if(GUI.Button(newRect(50,250,200,30),"Button1")) { info = "按下了Button1"; } // 第二个图片按钮 GUI.color = Color.white; //按钮文字颜色 GUI.backgroundColor = Color.green; //按钮背景颜色 if(GUI.Button(newRect(50,300,128,64), buttonTexture)) { info = "按下了Button2"; } } }
相关文章推荐
- Kinect结合Unity3D引擎开发体感游戏(一)
- c#调用COM组件
- C#实现把指定数据写入串口
- C#动态创建button的方法
- C#中抽象方法与虚拟方法的区别
- c#中虚函数的相关使用方法
- C#实现给图片加水印的方法
- C#使用加边法计算行列式的值
- C#实现多线程的同步方法实例分析
- C#中尾递归的使用、优化及编译器优化
- C#中的delegate委托类型基本学习教程
- C#实现子窗体与父窗体通信方法实例总结
- C#通用邮件发送类分享
- 举例讲解C#中自动实现的属性
- C#中this的用法集锦
- C#数据结构之顺序表(SeqList)实例详解
- C#.NET获取拨号连接的宽带连接方法
- C#异步绑定数据实现方法
- C#实现AddRange为数组添加多个元素的方法