Layering 2D Graphics

Hi All,
I have looked, but can’t see!

Is there a way of layering (ordering) 2D graphics used as part of the new GUI calls.

I would like to be able to dynamically change which graphic is on top.

Thanks, Peter

In the new system, GUI elements are draw in the order they appear in your script: so the elements (windows, graphics, etc.) appearing at the top of your script are underneath and the elements at the bottom of your script are on top.

Besides that, if you make a window moveable, then give it focus (by clicking on it) it will be displayed on top. I’m not sure how (or if) this can be done through script though.

And just in case there was any confusion, all GUI class stuff is rendered on top of all the regular stuff drawn by the in-scene cameras (including their GUI Layer). So if you have a custom cursor ingame, it will go back the plain pointer when you are over GUI windows.

And yes, there’s a window focus function to change window focus under script control (you need to use it if you open a child window from a parent window, for example).

Don’t forget, you can also set GUI.depth to control the layering when you have GUI calls coming from multiple scripts.

GUI.depth

You mean the stacking of GUI class elements, right? That still doesn’t layer them with things rendered by the camera, no?

If you have OnGUI functions being called in different scripts, GUI.depth controls their layering among each other. None of this allows GUI elements to layer with in-scene content as all GUI stuff is drawn on top.

As I thought – thanks for the further clarification, Tom.

Thanks everyone.
The GUI.depth sounds what I am after. I am wanting to ensure that my menu buttons are always on top, even when the interface changes.
Peter

silly question. but what range of numbers does GUI.depth look for? I set mine between 10 and 100 and it still isn’t drawn above the other gui elements being called by other scripts in OnGUI.

[edited] OK found it out for myself… went against logic (to me anyway) and used -1. Now my element is above all others. Might be nice to mention that in the documentation…

Cheers.