text variable unity code example
Example 1: text variable type unity
using UnityEngine;
using UnityEngine.UI; //make sure to add this!
public class Script : MonoBehaviour
{
public int counter = 0;
public Text variable; //make reference in Unity Inspector Window
void Update()
{
counter++;
variable.text = "counter: " + counter;
}
}
Example 2: how to make text show a variable in unity
using UnityEngine.UI; //its a must to access new UI in script
public class YourClass : MonoBehaviour
{
public Text Score_UIText; // assign it from inspector
void Start()
{
Score_UIText.text = yourscore_variable;
}