Hi, I have a Unity scene that has different GUI textures that are reside on two layers (basically a background and some button icons over this background); I’ve put all the background elements in one gameObject and all the buttons into another gameObject; I can’t figure out with what criteria Unity is using to draw the two things: sometimes the draw order is correct, but sometimes you compile again, without changing nothing and the draw order is reversed (background on top of buttons).
Has anyone ideas on how to control this in a deterministic way ?
Ultimately it is up to the order of execution for each GameObject which you don’t have precise control over. If you want to force a particular layering order then look into using GUI.depth.
I was suspecting that; while waiting for an answer from the forum I started shuffling the Unity documentation and found GUI.depth, but doesn’t seem to work either.
I tried to attach the script
var myDepth : int;
function Awake() {
GUI.depth = myDepth;
}
to the GUI texture, but with no results; changing the number on the two textures that I’m using doesn’t change the overlapping order…
You need to set GUI.depth in OnGUI() every run.
-Jeremy
Sorry, but the issue concerns GUITextures, how can I use OnGUI to set parameters of GUITextures ? UnityGUI and GUI are supposed to be two different items…
This is why it’s good to clarify whether you’re using UnityGUI (which supports GUI.depth) or GUIText/GUITextures (or for those like us helping it’s good for us to ask up front if we’re not clear). Your initial post confused me a bit as you wrote “GUI textures” would led me to believe you were using UnityGUI and thus my suggestion. If you’re using GUITextures then you’re right, things like GUI.depth won’t help at all as that’s an entirely different system. In the case of GUITextures a read of the documentation should prove helpful:
Near the bottom of that page you’ll see the following:
The depth of each layered GUI Texture is determined by its individual Z Transform position, not the global Z position.
So control your layering by setting the z-position for your various GUIText/GUITexture objects and you should be all set!
But what if the guiText and GuiTexture are components of the same object? Then they share the same z position and its impossible to change them.
I find this a problem because this means I need to have two objects (drawcalls) for every button (guitexture) that has text(guitext) on top.
That would use two draw calls anyway; just making the GUIText and GUITexture components of the same object doesn’t combine them in any way.
–Eric
Ive been trying this recently and the visual ordering is fine but when it comes to detecting touches with the ipod sometimes textures on top arent detected (the one under it is)…but then if you just reassign the box collider it works fine!.. but then other guitexture button detections in the same scene stop working. Its a really wierd bug.
Does anyone know a bulletproof way of tracking guitexture touches on iphone?