GUI.depth Questions

Hello, I’m trying to create file tab like system in the OnGUI() function. I’m using the GUI.depth property to attempt to change the depth of the selected tab.
Here is my code:

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class TabGui: MonoBehaviour
{
    public int tabOneDepth;
    public int tabTwoDepth;

    public GUISkin tabSkin;

    public Rect backgroundRect;
    public Rect tabRect;

    void OnGUI()
    {
        GUI.skin = tabSkin;
        #region MainBackground
         GUI.BeginGroup(new Rect(230, 0, 570, 768));
         GUI.Box(backgroundRect, "", "Background");
         GUI.EndGroup();
        #endregion

        #region Tabs
         GUI.BeginGroup(new Rect(0, 0, 230, 768));
         #region BodyTab
          TabOne(tabOneDepth);
         #endregion

         #region ClothesTab
          TabTwo(tabTwoDepth);
         #endregion
         GUI.EndGroup();
        #endregion
    }

    public void TabOne(int depth)
    {
        GUI.depth = depth;
        GUI.Box(tabRect, "", "TabOne");

        if (depth == 0)
        {

        }
    }

    public void TabTwoTab(int depth)
    {
        GUI.depth = depth;
        GUI.Box(tabRect, "", "TabTwo");

        if (depth == 0)
        {

        }
    }
}

However no matter what the depth of either function, TabTwo is always on top.

Thanks,
Hans

Here’s a question I asked on the same topic:

Long story short:

You have to draw overlapping controls in separate scripts if you want to control the layering.