用JS写Unity3D脚本的时候如何改变Button里的字体大小?

代码如下
if(GUI.Button(Rect(0,0,100,100),"Hello")){
}
现在想问如何根据按钮的大小来改变显示出来的"Hello"的字体大小呢?

你好,这是我以前用过的代码,请参考:
void OnGUI() {
// Create style for a button
GUIStyle myButtonStyle = new GUIStyle(GUI.skin.button);
myButtonStyle.fontSize = 50;

// Load and set Font
Font myFont = (Font)Resources.Load("Fonts/comic", typeof(Font));
myButtonStyle.font = myFont;

// Set color for selected and unselected buttons
myButtonStyle.normal.textColor = Color.red;
myButtonStyle.hover.textColor = Color.red;

...

// use style in button
bool testButtonTwo = GUI.Button(new Rect(10,10,50,50), "test", myButtonStyle);

...
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2018-03-02
GUI.skin.button.fontSize = 25;本回答被网友采纳
第2个回答  2014-11-14
原生GUI的话,改变字体大小,用GUIStyle比较好,也就是多定义一个参数,看看API,很清楚追问

我是新手。那个GUIStyle怎么设置参数呢。比如if(GUI.Button(Rect(0,0,100,100),"Hello",GUIStyle.fontSize=26)){
} ,但是这样不对。

相似回答