1

如何对其进行编程,以便我可以将字体类型更改为:Coalition 或 Arial...

这是我当前的代码...

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 + "";
    }
}
4

1 回答 1

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
    }

}

如果您的标签设置为使用位图字体,则您需要将UIFont分配给label.bitmapFont

于 2014-08-19T15:41:06.283 回答