Version: 2017.2
public static int depth ;

描述

当前正在执行的 GUI 行为的排序深度。

设置该属性可以确定同时运行的多个不同脚本的排序。 使用较小深度值绘制的 GUI 元素将显示在深度值较大的元素上方(您可以将深度想象为到摄像机的“距离”)。

注意:要使该示例正常工作,您需要创建 2 个脚本。 请记得将脚本命名为与类名称相同的名称, 否则示例代码将不起作用。

\ 一个按钮位于另一个的后方。

// Makes this button go back in depth over the example2 class one.
class example1 extends MonoBehaviour {
    static var guiDepth : int = 0;
    function OnGUI() {
        GUI.depth = guiDepth;
        if(GUI.RepeatButton(Rect(0,0,100,100), "GoBack")) {
            guiDepth = 1;
            example2.guiDepth = 0;
        }
    }
}

将此另一个示例复制到另一个脚本:

// Makes this button go back in depth over the example1 class one.
class example2 extends MonoBehaviour {
    static var guiDepth : int = 1;
    function OnGUI() {
        GUI.depth = guiDepth;
        if(GUI.RepeatButton(Rect(50,50,100,100), "GoBack")) {
            guiDepth = 1;
            example1.guiDepth = 0;
        }
    }
}
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961