- Home /
GUI Depth not working
I have two different scripts that draw GUI elements.
The first script draws 3 GUI elements, and I use GUI.Depth to place the elements on top of each other: // Draws the background GUI.depth = -1000; Rect backgroundRect = new Rect(0, 0,Screen.width, Screen.height); GUI.DrawTexture(backgroundRect,sceneBackground);
GUI.depth = 0;
// Draws the back button
GUI.backgroundColor = new Color(0,0,0,0);
if(GUI.Button(new Rect(10, 10, backButton.width / 2f, backButton.height / 2f), backButton))
{
Application.LoadLevel("Menu");
}
// Draws the camera GFX
Rect cameraGFXRect = new Rect(
(Screen.width / 2) - cameraGFX.width / 4,
(Screen.height / 2) + cameraGFX.height / 4,
cameraGFX.width / 2f,
cameraGFX.height / 2f);
GUI.DrawTexture(cameraGFXRect,cameraGFX);
Then the second script draws a rectangle in the center of the screen, also using GUI.Depth to draw the rectangle above the other GUI elements that already appear on screen:
GUI.depth = 10;
Rect cardRect = new Rect((Screen.width / 2) - (cardTexture.width / 4), (Screen.height / 2) - (cardTexture.height / 4), cardTexture.width / 2 , cardTexture.height / 2);
GUI.DrawTexture(cardRect,cardTexture);
Even though the first elements were drawn at a depth of -1000 and 0, and the second script draws at depth of 10, the GUI element from the second script appears below the elements from the first script??
I would very much appreciate it if someone could explain what I am doing incorrectly?
TIA!
You are correct, the smaller the number the closer it is to me, I got confused because this is the opposite of how one normally positions objects in 3D space. But thanks for your help! (If you change your comment to an answer I will mark it as answered!)
Answer by Nerevar · Jul 08, 2014 at 03:55 PM
GUI.depth is taken in account on separated scripts, in your first script doing
GUI.depth = -1000;
and then
GUI.depth = 0;
will be ineffective.
the higher the value of GUI.depth is, the further your GUI elements are behind. you may have took it the wrong way :p
Your answer
Follow this Question
Related Questions
Reduce Draw call for Multiple GUI Textures with same Texture 1 Answer
GUI depth? 1 Answer
How to control GUITextures within a single C# script? 1 Answer
GUI 2D Bounding Box 1 Answer
Move GUI elements. 0 Answers