2014-04-23 23 views
1

如果標題很醜,我很抱歉。使GUI Box的底角保持原位

的事情是:我已經做了GUI框在Unity這樣的:

enter image description here

如果您在圖片2看到,有上有一個空的空間,我不不想那樣。我想要的是底部的角落是留在像圖片1,只有它的頂角不斷增長,但底部保持在原地。

下面是一個例子圖像(從超神英雄拍攝):

enter image description here

如果您在圖片1看到,有它的文本在框的底部邊角,都撐在屏幕的底部角落,如果你看圖片2並與圖片1進行比較,只有Box的頂部角落增長到頂部(減去屏幕分辨率)和底部角落停留在屏幕分辨率的底部角落。

有沒有什麼辦法可以做到這一點?

這裏是我使用的代碼:

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."; 
    GUIStyle style; 
    GUIContent boxText; 

    void OnGUI() 
    { 
     boxText = new GUIContent("" + textOnBox); 

     GUI.color = new Color(0, 0, 0, 0.9f); 

     style = new GUIStyle(GUI.skin.box); 
     style.alignment = TextAnchor.MiddleLeft; 

     Rect boxGUI = GUILayoutUtility.GetRect(boxText, "Box"); 

     boxGUI.x = Screen.width/2 + 50; 
     boxGUI.y = Screen.height/2 + 200; 

     GUI.Box(boxGUI, boxText, style); 
    } 

你的回答非常感謝! 非常感謝!

回答

0

從你的風格的字體大小可用於確定3行文本的高度框的大小,你可以做

style.fontSize * 3;