- Home /
How to get health values into 3DTextMesh
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?
Answer by Owen-Reynolds · Nov 22, 2013 at 05:09 AM
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 (http://docs.unity3d.com/Documentation/ScriptReference/TextMesh.html). 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( ... .
Your answer
Follow this Question
Related Questions
Spawing small sprites proportionate to health 0 Answers
How To Make Player Health Increase if in a Certain Animation State 1 Answer
Player health dropping far to fast 1 Answer
how do u make diffrent chacters and give them commands 2 do things 2 Answers
Problem with substracting life to multiple gameObjects (c#) 2 Answers