如何在Unity中更改字体类型? [英] How to change Font type in Unity?

查看:1112
本文介绍了如何在Unity中更改字体类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How do I program it so that I can change the font type to: Coalition or Arial...

这是我当前的代码...

Here is my current code...

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

推荐答案

下面是一个示例,该示例如何更改在 UILabel 中使用动态字体的UILabel的字体. NGUI .

Here is an example of how to change the font of a UILabel that uses a dynamic font in NGUI.

标签会以原始字体显示一些文本2秒钟,然后切换到另一种字体(您在检查器中分配给 otherFont 的字体)

The label shows some text in the original font for 2 seconds, then switches to the other font (the one you assign to otherFont in the inspector)

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 .

If your label was set to use a bitmap font, you'd assign a UIFont to label.bitmapFont instead.

这篇关于如何在Unity中更改字体类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆