text variable type unity

C#
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;
    }
}
Source

Also in C#: