Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

GUI render order.

Discussion in 'Immediate Mode GUI (IMGUI)' started by Marc, Nov 28, 2007.

  1. Marc

    Marc

    Joined:
    Oct 4, 2007
    Posts:
    499
    Is there a way to control the order in which GUI is drawn?

    Say i have two game objects A and B who draws their own gui GA and GB using the OnGUI method. Now i want to make sure that GA is always drawn ontop of GB is there a way to control this?

    Regards,
    Marc
     
  2. User340

    User340

    Joined:
    Feb 28, 2007
    Posts:
    3,001
    I think you would set the depth of the gui.

    Code (csharp):
    1. function OnGUI ()
    2. {
    3.      // This will be drawn below
    4.      GUI.depth = 2;
    5.      GUI.Box (Rect (), "Box");
    6.      
    7.      // This will be drawn on top
    8.      GUI.depth = 4;
    9.      GUI.Box (Rect (), "Box2");
    10. }
     
  3. Marc

    Marc

    Joined:
    Oct 4, 2007
    Posts:
    499
    Thanks!

    That works, but you seem to have reversed what will be on top. Lower numbers seem to go infront og higher.
     
  4. NicholasFrancis

    NicholasFrancis

    Joined:
    Apr 8, 2005
    Posts:
    1,587
    Actually, that won't quite work when you throw input into the mix.

    Then you either need to use Window (if you want click-to-bring-to-front behaviour), or put your two pieces of GUI into seperate scripts, then set the depth of each script.
     
  5. Marc

    Marc

    Joined:
    Oct 4, 2007
    Posts:
    499
    That is what i did as my gui is component based and each component can create its own gui to control it :D

    Thanks for the help all.

    Cheers,
    Marc