- Home /
making a GUI.Label displayed behind spawned gameobject
hi everybody.
i've created a GUI.Label for my 2d game that shows the score. in my game there are spawned gameobject that fall down in the scene from the top of the screen.
i've placed my GUI.Label in the upper center of the screen. the problem is that my spawned object are displayed behind the GUI.Label: they are covered by the score.
is there any solution to make the Label diplayed behind the spawned object?
i instantiate my object giving a position like
Vector3 pos8 = new Vector3 (xValue, yValue, 0);
so they're created at a z=0 position.
the z position of the GameObject on which is attached the script that creates the GUI.Label is set at 10 but the score is still in foreground.
i've also tried to assign a positive depth to my label in this way:
void OnGUI(){
GUI.depth = 10;
GUI.Label (rett, " " + playerScore , style);
}
but is still not working.
thanks for any help!
did u found any solution? I am having the same problem. :(
GUI.depth is the right way, but it'S the other way around. Scripts with smaller depths are rendered BEFORE those with higher depths. Also remember that the onGUI function is ran from top to bottom, with the stuff that comes later rendered above stuff that comes earlier. Also remember that GUI.depth can only be used once in a OnGUI function, if GUI stuff with a different depth is needed, is has to be in it's own script and OnGUI function.