Working with GUI.depth

I created combo boxes ( a total of 4) for my application and they are stacked one beneath the other with a little bit of space between them. But the problem I am having is that the top combo box’s drop down list is being drawn behind the second combo box, and that one’s drop down list is being drawn behind the third one, so on and so forth. The only one who’s fine is the fourth combo box and its because that is the last one in the list. If I had a fifth combo box I’m sure I would have the same issue.

I read somewhere that I need to create separate classes and in each OnGUI method I should give a different GUI.depth value so that way one is not drawn on top of another.

So what I went ahead and did is I created a script that has 5 classes: the main class handles displaying the combo boxes and the other four are where I create each combo box. Each class has its own OnGUI method and I give them a GUI.depth like:

public ComboBoxClass_1
{
    void OnGUI()
    { 
      GUI.depth = 1;
    }  
} 
public ComboBoxClass_2
{
    void OnGUI()
    { 
      GUI.depth = 2;
    }  
}
public ComboBoxClass_3
{
    void OnGUI()
    { 
      GUI.depth = 3;
    }  
}
public ComboBoxClass_4
{
    void OnGUI()
    { 
      GUI.depth = 4;
    }  
}

But my when I run the application my combo boxes are still having depth or layer issues. Can someone please tell me what I am doing wrong? Many thanks in advance!

1 Answer

1

In each of your scripts, in the start function, set useGUILayout = false;