How do I link a variable to text

I am very new to Unity but everything I look up in relation to this doesn’t work. I want a variable to appear on the screen in a text object and I want the text object to equal the variable and I want the maximum value to be 100 and the minimum to be 0.

Have you checked TextMesh Pro Tutorial ?

Your variable is in some script. Hopefully that script derives from MonoBehaviour (or some subclass thereof). So, give that script also a property of type TextMeshProUGUI, and then set the text of that in your Update method, e.g.:

public TextMeshProUGUI displayText;

void Update() {
    displayText.text = myVariable.ToString();
}

Now in the Inspector for whatever object this script is on, drag the TextMeshPro text into the displayText slot. That should do it.

Try this, and if it doesn’t work, explain exactly how it doesn’t work, and we’ll help.

1 Like

A slot doesn’t appear in the inspector and I got an error that the name doesn’t exist in the current context

[SerializeField] float nameoffield

That is how you make a field in the inspector for a variable with a float value. This should be right under your class. If no decimals you can use int. You need to call it with the ToString(); method that was provided above. It would be easier if you gave us a code example.

2 Likes

You probably need to add “using TMPro;” to the top of your script, but we can only guess since you didn’t copy/paste the actual error message, nor show us your code.

If you’re going to ask people for help, you should at least take the time to provide all the detail they might need to help you.