- Home /
Change the content of a Text Mesh
Hi there
I have a 3d text gameObject and i want the Text Mesch to display a vareable.
Simple Question: How do i do this?
My script:
var number=0; var text="0";
function Update () {
number=PlayerPrefs.GetInt("points");
text=number.ToString;
//Display the vareable "text"
}
I have no idea since i tried everyrhing...
Thanks for your attention =)
Have you look at the documentation? This is what you need: http://docs.unity3d.com/Documentation/ScriptReference/Text$$anonymous$$esh-text.html
If is the same game object you can use exactly this code above, in the documentation.
Thanks for your answers but i cannot test it because suddenly i got an error like: "cannot convert function():string to string"
Probably is cause you have to use this: text=number.ToString(); ->> you dind't put the ()
Answer by BBoulder · Jan 25, 2013 at 11:02 PM
I think you need to use this:
GetComponent(TextMesh).text = text;
Is your script on the same game oject as the script?
Your answer
![](https://koobas.hobune.stream/wayback/20220613091603im_/https://answers.unity.com/themes/thub/images/avi.jpg)