- Home /
GUI.depth for use in same script or inherited script
Hello ppl,
I want to know if there's a method of managing my GUI.Drawtexture depth if I don't want to use a different script.
I have a base class, I though of putting GUI.depth=1 in there and 2 in the inherited one, but still not working, it must be treating them as "not different" scripts.
I can use a different scirpt though but its really silly, image 4 depths? 4 scripts for OnGUI()?
there must be an alternative, also I though of a front cam of a higher depth.. but not sure if able to apply chosen cam to my drawn GUI.DawTexture..(while for GUITexture its simple).. also doesn't sound a fine solution
But I think someone could help me with the better one.
thanks for ur time
Post your classes because it's not clear what the base class is doing and what your subclass is for. Things in OnGUI get drawn in the exact order you call them. They are drawn immediately, so there's no way of sorting them. Unity can of course change the order in which the OnGUI functions are called, but only per script.
public class BaseClass : $$anonymous$$onoBehaviour
{
public Texture2D loadingBgImage;
protected Rect fullScreen;
protected virtual void OnGUI()
{
GUI.depth = 1;
if(loading)
GUI.DrawTexture(fullScreen,loadingBgImage,Scale$$anonymous$$ode.StretchToFill ,true,0);
}
}
public class LevelSelection_Controller : BaseClass
{
protected override void OnGUI()
{
base.OnGUI();
GUI.depth = 2;
if(GUI.Button(buttonsRectArray[0] , currentButtons[0] , buttonGUIStyle))
{
GameController.SetStartingLevel(1);
loading = true;
Application.LoadLevel("Game");
}
if(GUI.Button(buttonsRectArray[1] , currentButtons[1] , buttonGUIStyle))
{
GameController.SetStartingLevel(2);
Application.LoadLevel("Game");
}
}
@Bunny83 , so here's the code as you see.. I want loading to code front (its a png texture with 50% opacity)
am I obliged to have it on a separate script?
@Jamora it did work !! great please post an answer so that I can tick as true. Thanks a lot, but I couldn't understand why it acts like this.. I wonder what has calling the base class OnGUI function first or calling the LevelSelection_Controller OnGUI function first, to do with setting the GUI.depth.. a bit stange but it works as I wanted
Answer by Jamora · Aug 21, 2013 at 11:36 AM
Move the base.OnGUI();
call to the end of the OnGUI
in LevelSelection_Controller
.
The GUI is rendered in the same order as the script is written, so things that are earlier in script are rendered behind things that are later in the script.
//GUI Render Order
GUI.Label(aRect,"Deepest");
GUI.Label(aRect,"Above Deepest, but below the next label");
GUI.Label(aRect,"Above everything else");
Dude GUI.depth has nothing to do here.. its just the order of executed as you mentioned
Answer by Ejlersen · Aug 20, 2013 at 08:27 PM
If its the same OnGUI call, which it is, then setting the GUI.depth multiple times won't work. Its per OnGUI call.
sure dude, and that's what I'm telling and searching the solution for. If GUI.depth doesn't work, then sure to be an alternative..
Then you either have to create your own gui system, that does the sorting for you. Or have several OnGUI calls, but thats expensive.
true, that's expensive and seems ugly to have a separate script just for the purpose of layering... thanks for ur help
Your answer
![](https://koobas.hobune.stream/wayback/20220613112612im_/https://answers.unity.com/themes/thub/images/avi.jpg)