参考文章:
Unity3D修改Font字体
Unity GUI设置字体大小
1、用GUIStyle来设置字体样式
-
<pre name="code" class="csharp"><pre name="code" class="csharp">void OnGUI()
-
{
-
GUIStyle fontStyle = new GUIStyle();
-
fontStyle.normal.background = null; //设置背景填充
-
fontStyle.normal.textColor= new Color(1,0,0); //设置字体颜色
-
fontStyle.fontSize = 40; //字体大小
-
GUI.Label(new Rect(0, 0, 200, 200), "Hello Font", fontStyle);
-
}
2、用GUI.skin更换字体(例如楷体)
// 后面的color为 RGBA的格式,支持alpha,取值范围为浮点数: 0 - 1.0 GUI.skin.label.normal.textColor = Color( 0, 255.0/255, 0, 1.0 ); GUI.skin.label.font = customFont; GUI.Label( Rect(0,100,100,100), "show text" );
根据需要先在inspector面板修改字体ttf文件的属性,例如字体大小等,然后将Assert中的字体拖入customFont变量则可替换字体。
|