如何进行编程,以便可以将字体类型更改为: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 + "";
}
}
这是一个如何更改在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。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句