How to change font type in Unity?

How to program it to 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 + ""; } } 
+1
source share
1 answer

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

The label shows the text in the original font for 2 seconds, then switches to another font (the one you assign to another font 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 } } 

If a raster font was installed on your label , you must assign UIFont to label.bitmapFont .

+1
source

Source: https://habr.com/ru/post/989227/


All Articles