簡體   English   中英

Unity Gui fontSize不變

[英]Unity Gui fontSize dont change

我在下面使用此代碼在Android游戲的GameOver屏幕上添加“ RetryQuit按鈕。

//if retry button is pressed load scene 0 the game
    if(GUI.Button(new Rect(Screen.width/2-50,Screen.height/2 +100,200,140),"Retry?")){
        Application.LoadLevel(0);
    }
    //and quit button
    if(GUI.Button(new Rect(Screen.width/2-50,Screen.height/2 +200,200,140),"Quit")){
        Application.Quit();
    }

但是Gui文本的fontSize很小,無論我嘗試什么,都無法使其變大。 我該怎么解決。

為此使用樣式對象。

    GUIStyle style = new GUIStyle();
    style.fontSize = 20;
    if(GUI.Button(new Rect(Screen.width/2-50,Screen.height/2 +100,200,140),"Retry?", style)){
        Application.LoadLevel(0);
    }
    //and quit button
    if(GUI.Button(new Rect(Screen.width/2-50,Screen.height/2 +200,200,140),"Quit", style)){
        Application.Quit();
    }

但這將覆蓋原始樣式,因此您可能還需要進行其他一些更改。 例如,將這些行放在“ style”的聲明之后和首次使用之前:

    style.alignment = TextAnchor.MiddleCenter;
    RectOffset margin = new RectOffset();
    margin.bottom = 10;
    margin.top = 10;
    style.margin = margin;
    style.normal.background = new Texture2D(1, 1);

有關所有可能的設置,請查閱統一手冊。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM