- Home /
The question is answered, right answer was accepted
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?
Answer by Bunny83 · Dec 29, 2012 at 10:38 AM
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.
thank you that was exactly what I was searching for! I just created a new Window and did it on the top and that worked fine :D
Answer by Geo.Ego · Dec 28, 2012 at 07:57 PM
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.
well I did but it doesn't do it anyway? $$anonymous$$aybe because of the window in front of it:
windowRect = GUI.Window (0, windowRect, Window, ""); if(draggedItem != 0){ GUI.DrawTexture(Rect(Input.mousePosition.x,Screen.height-Input.mousePosition.y,size.x - 5,size.y - 5), manager.textures[draggedItem-1], Scale$$anonymous$$ode.StretchToFill, true, 10.0f); }
Answer by Itinerant · Dec 28, 2012 at 08:04 PM
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.
Follow this Question
Related Questions
DIALOGUE BRANCH CREATION? 1 Answer
How do I make a custom font for a GUI button? C# 1 Answer
Tutorials for 2D game GUI 2 Answers