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
1
Question by moghes · Aug 20, 2013 at 12:32 PM · cameraguitexturegui.drawtexturegui.depth

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

Comment
Add comment · Show 5
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 Bunny83 · Aug 21, 2013 at 07:38 AM 0
Share

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.

avatar image moghes · Aug 21, 2013 at 08:29 AM 0
Share
 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");                            
     }

}

avatar image moghes · Aug 21, 2013 at 08:32 AM 0
Share

@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?

avatar image moghes · Aug 21, 2013 at 12:46 PM 0
Share

let me try that

avatar image moghes · Aug 21, 2013 at 01:37 PM 0
Share

@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

2 Replies

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

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");
Comment
Add comment · Show 1 · 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
avatar image moghes · Aug 21, 2013 at 02:13 PM 0
Share

Dude GUI.depth has nothing to do here.. its just the order of executed as you mentioned

avatar image
0

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.

Comment
Add comment · Show 3 · 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
avatar image moghes · Aug 20, 2013 at 08:57 PM 0
Share

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..

avatar image Ejlersen · Aug 21, 2013 at 07:16 AM 0
Share

Then you either have to create your own gui system, that does the sorting for you. Or have several OnGUI calls, but thats expensive.

avatar image moghes · Aug 21, 2013 at 08:34 AM 0
Share

true, that's expensive and seems ugly to have a separate script just for the purpose of layering... thanks for ur help

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

18 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Instantiated GuiTextures not showing 1 Answer

Object showing different when Build into Mobile 0 Answers

How to draw a Gui.Layer to a especific camera. 0 Answers

How do I make a border decoration effect? 1 Answer

Is it possible to make guitexture above gui.drawtexture? 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