[英]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. 我在下面使用此代码在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();
}
But the fontSize of the Gui text is so small and no matter what I try then I cant make it bigger. 但是Gui文本的fontSize很小,无论我尝试什么,都无法使其变大。 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”的声明之后和首次使用之前:
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. 有关所有可能的设置,请查阅统一手册。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.