- Home /
I can't change the text mesh
Hello,
I want to change the text of the TextMesh component of a Game Object. I added this script, but it doesn't work. What's wrong?
#pragma strict
var scorePoints : int;
function Start () {
}
function Update () {
TextMesh.text = scorePoints;
}
I am receiving AN error. All tutorials say that .text in transform.GetComponent (Text$$anonymous$$esh).text works and even in the component on the inspector there is a value called 'Text', however this nor any other part of the component can be referenced in the script.
"The same error"? What error? Where's your code?
Sorry, i edited the first sentence. I used transform.GetComponent (Text$$anonymous$$esh).text ins$$anonymous$$d of Text$$anonymous$$esh.text because it was more updated to the Unity 5, and then this error occurred.
Answer by rober-psious · May 09, 2016 at 08:38 AM
TextMesh.text = scorePoints;
You are calling a static method "text". If you want change the value of the text component of your object, you can try with the next code:
var scorePoints : int = 5;
var myTextMesh : TextMesh;
function Start()
{
myTextMesh.GetComponent(TextMesh);
}
function Update()
{
myTextMesh.text = scorePoints;
}
Your answer
Follow this Question
Related Questions
Unity crashes at writing TextMesh? 0 Answers
Text Mesh to Mesh ? 2 Answers
Adding vertices to TextMesh Pro 0 Answers
Problem with displaying a value digitally 1 Answer
Wrapping a Textmesh text 5 Answers