Search Unity

[Issue] GUI disappears on certain screen position

Discussion in 'Immediate Mode GUI (IMGUI)' started by YDrogen, Nov 5, 2016.

  1. YDrogen

    YDrogen

    Joined:
    Nov 5, 2016
    Posts:
    2
    Hi everyone !

    I'm getting started with Unity and I am now following a tutorial in which it asks me to draw a GUI box (with OnGUI()).

    This piece of code works great :
    Code (CSharp):
    1.  
    2. private const int ORDERS_BAR_HEIGHT = 150;
    3. private void DrawOrdersBar() {
    4.         // Screen coordinates (0,0) is TOP-LEFT corner
    5.  
    6.         Rect rect = new Rect (0, 0, Screen.width, ORDERS_BAR_HEIGHT);
    7.         GUI.skin = ordersSkin;
    8.         GUI.BeginGroup (rect);
    9.         GUI.Box (rect, "Orders Bar");
    10.         GUI.EndGroup ();
    11.     }
    It draws this :

    But as soon as I want to put that rect on the bottom of the screen, like this...
    Code (CSharp):
    1. private const int ORDERS_BAR_HEIGHT = 150;
    2. private void DrawOrdersBar() {
    3.         // Screen coordinates (0,0) is TOP-LEFT corner
    4.         Rect rect = new Rect (0, Screen.height - ORDERS_BAR_HEIGHT, Screen.width, ORDERS_BAR_HEIGHT);
    5.         GUI.skin = ordersSkin;
    6.         GUI.BeginGroup (rect);
    7.         GUI.Box (rect, "Orders Bar");
    8.         GUI.EndGroup ();
    9.     }
    It draws this...
    It does not appear and I don't get why !
    If someone knows how to fix this, I'll be there ! :)
    Thanks !
     
  2. PsyKaw

    PsyKaw

    Joined:
    Aug 16, 2012
    Posts:
    102
    In the documentation of BeginGroup : "When you begin a group, the coordinate system for GUI controls are set so (0,0) is the top-left corner of the group."

    So put your box in 0,0
     
  3. YDrogen

    YDrogen

    Joined:
    Nov 5, 2016
    Posts:
    2
    Hi @PsyKaw !
    Have you read my post ? It's what I did first to get it on top of the screen, and worked well but I wanted to make that box on the bottom of the screen which disappeared when I did that too.
    Anyway, I moved on and used the Unity UI system which work way better to do what I wanted to do.

    Thanks !
     
  4. PsyKaw

    PsyKaw

    Joined:
    Aug 16, 2012
    Posts:
    102
    Hi @YDrogen !

    I've read your post and you don't undertand my answer, if you do like this :
    Code (csharp):
    1.  
    2. private const int ORDERS_BAR_HEIGHT = 150;
    3. private void DrawOrdersBar() {
    4.        // Screen coordinates (0,0) is TOP-LEFT corner
    5.        Rect rect = new Rect (0, Screen.height - ORDERS_BAR_HEIGHT, Screen.width, ORDERS_BAR_HEIGHT);
    6.        GUI.skin = ordersSkin;
    7.        GUI.BeginGroup (rect);
    8.        GUI.Box (Vector2.zero, "Orders Bar");
    9.        GUI.EndGroup ();
    10.    }
    11.  
    Anyway, the "new" UI system is a lot better to do ingame UI.