Hi, I am trying to get a text mesh displaying "Health: " to add in the actual health in the Text. I have 3 variables;
var maxHealth = 100;
var curHealth = 100;
var healthText : TextMesh;
I want to get the curHealth to show up in the text like this: “Health: 100/100” in game. How can I do this?
Two parts. One is how you get to the “show these words” part of a 3DText. The other is how you make “Health x/y”.
To make the phrase: "Health: " + curHealth + "/" + maxHealth
To put words in the 3DText, look at the Inspector components. The official name is TextMesh. Then note how the words are in a field named text.
Also look at the docs (Unity - Scripting API: TextMesh). They show text
and give an example.
Putting them together: GetComponent(TextMesh).text = "Health: " +
… ;
You’ll probably have a link to a textMesh, in the playerScript. In that case (look up finding other things,) it would be myHealthText.GetComponent(
… .