我正在使用下面的代码为我的安卓游戏添加一个Retry和Quit按钮到GameOver屏幕上。
//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是如此的小,无论我尝试什么,我都不能让它变大。我能做些什么来解决这个问题。
发布于 2014-11-11 14:55:21
为此使用样式对象。
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);对于所有可能的设置,请检查统一手册。
https://stackoverflow.com/questions/26866057
复制相似问题