简体   繁体   中英

Unity Gui fontSize dont change

I'm using this code below to add a Retry and Quit button to the GameOver screen for my android game.

//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();
    }

But the fontSize of the Gui text is so small and no matter what I try then I cant make it bigger. What can I do to solve this.

Use style object for this.

    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();
    }

But it is going to overwrite the original style so you probably want to make some other changes too. For example put these lines after declaration of ´style´ and before the first use of it:

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

For all possible settings check unity's manuals.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM