Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by ronnyvdb · Jul 08, 2014 at 03:44 PM · guiguitexturedepth

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!

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ronnyvdb · Jul 08, 2014 at 04:02 PM 0
Share

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!)

avatar image Nerevar · Jul 08, 2014 at 09:39 PM 0
Share

ok I did it :p

cheers

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

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

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges