![](/img/trans.png)
[英]In Unity GUI, when change button fontsize, how to change button size to wrap text
[英]Unity Gui fontSize dont change
我在下面使用此代码在Android游戏的GameOver
屏幕上添加“ Retry
并Quit
按钮。
//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.