CSS -> z-index, GUI -> ?

Hi!

Is there something like a z-index also in GUI? So that the Gui Button with the highest z-index is the one that is shown on top of all?

BTW: I know that it goes with the order of the buttons, but is there another way?

Sorry, it’s strictly determined by draw order. If you want a GUI element to be drawn on top of another, you have to draw it afterwards.

You have to distinguish between things drawn in OnGUI and things drawn in a window callback. Like the others already explained the order for things drawn In OnGUI depends only on the execution order since unity uses an immediate mode. At the moment a line is executed it will be rendered on screen.

GUI.depth can be used to tell unity in with order you want different scripts be executed.

Additionally to that there are windows. Windows aren’t drawn immediately when you call the Window function. Unity will store each window internally and specifies a separate render order which takes place after all OnGUI stuff is finished. Windows are always be drawn above the “normal” GUI. Which window is the top most can be controlled with:

Just read the window reference carefully. It doesn’t cover everything but the most important things.

There is slightly more to it than draw order, but not much. You can use http://docs.unity3d.com/Documentation/ScriptReference/GUI-depth.html

However, that’s a by-script sort of thing. So if you have GUIs in two different scripts, you can stack them how you want. For general use, though…it’s all about the draw order, just like Geo said.