using UnityEngine; namespace TMPro.Examples { public class TMP_ExampleScript_01 : MonoBehaviour { public enum objectType { TextMeshPro = 0, TextMeshProUGUI = 1 } public objectType ObjectType; public bool isStatic; private TMP_Text m_text; private const string k_label = "The count is <#0080ff>{0}"; private int count; private void Awake() { if (ObjectType == objectType.TextMeshPro) { m_text = GetComponent() ?? base.gameObject.AddComponent(); } else { m_text = GetComponent() ?? base.gameObject.AddComponent(); } m_text.font = Resources.Load("Fonts & Materials/Anton SDF"); m_text.fontSharedMaterial = Resources.Load("Fonts & Materials/Anton SDF - Drop Shadow"); m_text.fontSize = 120f; m_text.text = "A <#0080ff>simple line of text."; Vector2 preferredValues = m_text.GetPreferredValues(float.PositiveInfinity, float.PositiveInfinity); m_text.rectTransform.sizeDelta = new Vector2(preferredValues.x, preferredValues.y); } private void Update() { if (!isStatic) { m_text.SetText("The count is <#0080ff>{0}", count % 1000); count++; } } } }