首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >统一归集fontSize不变

统一归集fontSize不变
EN

Stack Overflow用户
提问于 2014-11-11 13:29:04
回答 1查看 2.2K关注 0票数 1

我正在使用下面的代码为我的安卓游戏添加一个RetryQuit按钮到GameOver屏幕上。

代码语言:javascript
复制
//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是如此的小,无论我尝试什么,我都不能让它变大。我能做些什么来解决这个问题。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-11-11 14:55:21

为此使用样式对象。

代码语言:javascript
复制
    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”声明之后和第一次使用它之前:

代码语言:javascript
复制
    style.alignment = TextAnchor.MiddleCenter;
    RectOffset margin = new RectOffset();
    margin.bottom = 10;
    margin.top = 10;
    style.margin = margin;
    style.normal.background = new Texture2D(1, 1);

对于所有可能的设置,请检查统一手册。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26866057

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档