Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Make the bottom corner of the GUI Box stay on place

Discussion in 'Immediate Mode GUI (IMGUI)' started by Yaako92, Apr 25, 2014.

  1. Yaako92

    Yaako92

    Joined:
    Apr 23, 2014
    Posts:
    4
    I am sorry if the title is ugly.

    The thing is: I already make the GUI Box in the Unity like this:

    $25650-untitled-2.jpg

    If you see on the Image 2, there is an empty space on there, and I don't want to be like that. What I want is the bottom corner is stay on place like the Image 1, only the top corner of it is growing, but the bottom stays on place.

    Here is an example image (taken from Heroes of Newerth):

    $25649-untitled-1.jpg

    If you see on the Image 1, the bottom corner of the Box that have texts on it, are stays on the bottom corner of the screen, and if you look at the Image 2 and compare it with Image 1, only the top corner of the Box that are growing to the top (minus with the screen resolution) and the bottom corner stays on the bottom corner of the screen resolution.

    Is there any way that I can do this?

    Here is the code that I am using:

    Code (csharp):
    1. string textOnBox = "This is an example on how does the text on the box is align.\nMy Name is ....\nI am new at Unity and want to learn more about Unity to create and publish my own game using this engine.";
    2.     GUIStyle style;
    3.     GUIContent boxText;
    4.  
    5.     void OnGUI()
    6.     {
    7.         boxText = new GUIContent("" + textOnBox);
    8.  
    9.         GUI.color = new Color(0, 0, 0, 0.9f);
    10.  
    11.         style = new GUIStyle(GUI.skin.box);
    12.         style.alignment = TextAnchor.MiddleLeft;
    13.  
    14.         Rect boxGUI = GUILayoutUtility.GetRect(boxText, "Box");
    15.  
    16.         boxGUI.x = Screen.width / 2 + 50;
    17.         boxGUI.y = Screen.height / 2 + 200;
    18.  
    19.         GUI.Box(boxGUI, boxText, style);
    20.     }
    Your answer much appreciated!

    Thank you very much!
     
  2. ajaykewat

    ajaykewat

    Joined:
    Jul 25, 2012
    Posts:
    22
    Put this line of code

    boxGUI.y =Screen.height - boxGUI.height ;

    instead of

    boxGUI.y = Screen.height / 2 + 200;

    Hope it works.

    ;)



     
  3. Yaako92

    Yaako92

    Joined:
    Apr 23, 2014
    Posts:
    4
    Thank you sir, it works :D