codecamp

OnGUI ToolTip 控件

Unity 3D ToolTip 控件主要用于显示提示信息。

当鼠标移至指定位置时,会显示相应的提示信息,在使用时需要和 GUI.Content 配合。

具体使用方法如下:

public static var tooltip:string

使用案例

  1. 创建项目,将其命名为 GUI.Tooltip,保存场景。

  1. 执行 AssetsCreateJavaScript 命令,创建一个新的脚本文件。

  1. 在 Project 视图中打开脚本编辑器,输入下列语句:

    function OnGUI(){
        GUI.Box(Rect(5, 35, 210, 175), GUIContent("Box", "this box has a tooltip"));
        GUI.Button(Rect(30, 85, 100, 20), "No tooltip here");
        GUI.Button(Rect(30, 120, 100, 20),
        GUIContent("I have a tooltip", "The button overrides the box"));
        GUI.Label(Rect(10, 40, 100, 40), GUI.tooltip);
    }

  1. Ctrl+S 键保存脚本。

  1. 在 Project 视图中选择脚本,将其连接到 Main Camera 上。

  1. 进行测试,效果如下图所示。

OnGUI ToolBar 控件
OnGUI Drag Window 控件
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }