Unity3D圣典3.3版本-中文版
文集大纲加载中……
本文档使用 MrDoc 发布
-
+
首页
GUI.Button 按钮
# [GUI](GUI.html "Go to GUI scripting documentation").Button 按钮 static function Button (position : Rect, text : String) : bool static function Button (position : Rect, image : Texture) : bool static function Button (position : Rect, content : GUIContent) : bool static function Button (position : Rect, text : String, style : GUIStyle) : bool static function Button (position : Rect, image : Texture, style : GUIStyle) : bool static function Button (position : Rect, content : GUIContent, style : GUIStyle) : bool ### Parameters**参数** * *position* Rectangle on the screen to use for the button. 用户按钮在屏幕上的矩形位置。 * *text* Text to display on the button. 在按钮上显示的文本。 * *image* Texture to display on the button. 在按钮上显示的纹理图片。 * *content* Text, image and tooltip for this button. 用于按钮的文本,图片和提示。 * *style* The style to use. If left out, the button style from the current GUISkin is used. 使用样式,如果不,按钮样式应用当前的 GUISkin 皮肤。 *Returns* bool - /true/ when the users clicks the button 当用户点击按钮的时候返回 true。 *Description* 描述 Make a single press button. The user clicks them and something happens immediately. 创建一个单次按下按钮。用户点击按钮事件立即触发。 * [C#](#) * [JavaScript](#) ``` using UnityEngine; using System.Collections; public class example : MonoBehaviour { public Texture btnTexture; void OnGUI() { if (!typeof(btnTexture)) { Debug.LogError("Please assign a texture on the inspector"); return; } if (GUI.Button(new Rect(10, 10, 50, 50), btnTexture)) Debug.Log("Clicked the button with an image"); if (GUI.Button(new Rect(10, 70, 50, 30), "Click")) Debug.Log("Clicked the button with text"); } } ``` ``` //绘制2个按钮一个有图像,另一个是文本 //当按钮被点击的时候打印信息 var btnTexture : Texture; function OnGUI() { if (!btnTexture) { Debug.LogError("Please assign a texture on the inspector"); return; } if (GUI.Button(Rect(10,10,50,50),btnTexture)) Debug.Log("Clicked the button with an image"); if (GUI.Button(Rect(10,70,50,30),"Click")) Debug.Log("Clicked the button with text"); } ```
da
2022年5月23日 13:42
转发文档
收藏文档
上一篇
下一篇
手机扫码
复制链接
手机扫一扫转发分享
复制链接
关于 MrDoc
觅思文档MrDoc
是
州的先生
开发并开源的在线文档系统,其适合作为个人和小型团队的云笔记、文档和知识库管理工具。
如果觅思文档给你或你的团队带来了帮助,欢迎对作者进行一些打赏捐助,这将有力支持作者持续投入精力更新和维护觅思文档,感谢你的捐助!
>>>捐助鸣谢列表
微信
支付宝
QQ
PayPal
Markdown文件
分享
链接
类型
密码
更新密码