Search Unity

Depth won't work

Discussion in 'Immediate Mode GUI (IMGUI)' started by mrgohut, Dec 14, 2014.

  1. mrgohut

    mrgohut

    Joined:
    Feb 8, 2014
    Posts:
    134
    Hello guys ! :D
    Inventory: http://scr.hu/3tpn/1t1hy
    And here is my problem:
    Code (csharp):
    1.  
    2.     void OnGUI() {
    3.         GUI.skin = dispSkin;
    4.         if(showOptions)
    5.         {
    6.             GUI.depth = 3;
    7.             GUILayout.BeginArea (new Rect (optionPos.x, optionPos.y, 80, 83));
    8.             if(itemS.itemSettings.isDropable) {
    9.                 if(GUILayout.Button("Drop", GUILayout.Width(80), GUILayout.Height(25)))
    10.                 {
    11.                     inv.DropItem(itemS);
    12.                     showOptions = false;
    13.                 }
    14.             }
    15.             if(itemS.itemSettings.isUsable) {
    16.                 if(GUILayout.Button("Use", GUILayout.Width(80), GUILayout.Height(25)))
    17.                 {
    18.                     Debug.Log("ItemUsed");
    19.                     //itemT.GetComponent<ItemEffect>().UseEffect();
    20.                     showOptions = false;
    21.                 }
    22.             }
    23.             GUILayout.EndArea ();
    24.             GUI.depth = 0;
    25.         }
    26.  
    27.         if (openUI) {
    28.             GUI.depth = 2;
    29.             wRect.character = GUI.Window(0, wRect.character, Character, "Character");
    30.             wRect.inventory = GUI.Window(1, wRect.inventory, Inventory, "Inventory");
    31.             GUI.depth = 0;
    32.         }
    33.     }
    so, when i click on my item in inventory options will be available to use:
    http://scr.hu/3tpn/e7c4d
    but the problem is... options are BEHIND inventory window despite the fact that I used
    Code (csharp):
    1. GUI.depth;
    someone know what's wrong ?
     
  2. AdamScura

    AdamScura

    Joined:
    Mar 25, 2012
    Posts:
    55
    Yes. I did some testing on this.

    Unity always renders GUI windows on top of the main GUI. It doesn't matter what you set the depth to. I've even tried putting the GUI window in a separate MonoBehaviour so I can control the depth independantly, and the result is always the same... GUI window on top.

    In your case, you've got a few options:
    1. Use a window for your options popup.
    2. Don't use windows for your character and inventory windows.
    3. Switch to the new GUI system included with Unity 4.6. It is a lot more powerful than OnGUI, and runs faster!
     
  3. mrgohut

    mrgohut

    Joined:
    Feb 8, 2014
    Posts:
    134
    Yeah, i tried to use new UI system, but i have problem with scaling on different resolutions :/