如何更改字体类型,统一?(How to change Font type in Unity?)

2019-09-30 08:51发布

怎样编程,以便我可以更改字体类型:联盟或宋体...

这是我当前的代码...

using UnityEngine;
using System.Collections;

public class InvSlotHandler : MonoBehaviour {

    private int excess = 1;
    UILabel lbl;

    void Start() {

        GameObject label = new GameObject();
        lbl = label.AddComponent<UILabel>();

        label.transform.name = "#QTY";
        lbl.fontStyle = FontStyle.Normal;
        lbl.fontSize = 15;
        lbl.alignment = NGUIText.Alignment.Right;

        NGUITools.AddChild (gameObject.transform.gameObject, label.gameObject);
    }

    void FixedUpdate() {
        lbl.text = gameObject.transform.childCount - excess + "";
    }
}

Answer 1:

下面是如何改变使用在NGUI一个动态字体一个UILabel的字体的实例。

标签显示在原字体2秒钟一些文字,然后切换到其他字体(分配给otherFont在检查一)

using UnityEngine;
using System.Collections;

public class ChangeFont : MonoBehaviour {

    public UILabel label; 
    public Font otherFont;

    IEnumerator Start() {
        label.text = "This is a bit of text"; //show text
        yield return new WaitForSeconds(2f); //wait 2 seconds
        label.trueTypeFont = otherFont; //change font
    }

}

如果您的标签被设置为使用位图字体 ,你会分配一个UIFontlabel.bitmapFont代替。



文章来源: How to change Font type in Unity?
标签: c# unity3d ngui