unity change text script code example

Example 1: unity change text

// To change text of a text UI element use th combination below
textGameObject.GetComponent<UnityEngine.UI.Text>().text = "text";

Example 2: unity how to change text in script

Text myText = GameObject.Find("Canvas/Text").GetComponent<Text>();
myText.text = "Your text changed!";

Example 3: unity change tmp text from script

using UnityEngine.UI;
using TMPro;

void Update()
{
    TextMeshPro lemonsss = GetComponent<TextMeshPro>();
}

Tags:

Misc Example