- Home /
What is wrong with my text changing script?
What is wrong with my text changing script?
var count = 10;
function Update() { var a = GameObject.Find ("MenCount1"); textMesh : TextMesh = a.GetComponent(TextMesh);
textMesh.text = count.ToString ();
}
Please Help. Thanks.
Answer by 3dDude · Jul 14, 2010 at 06:42 PM
you could try this
var count = 10;
function Update() { var a = GameObject.Find ("MenCount1"); var textMesh : TextMesh = a.GetComponent(TextMesh);
textMesh.text = count.ToString ();
}
when I change count variable text doesn't change...why is that?
are you sure you text$$anonymous$$esh is named $$anonymous$$enCount1?
Either way - you really shouldn't be a) grabbing the gameobject, then the component every frame b) setting the text every frame. Get the component once in start, then apply it only when count changes (and limit access to it to a function, so it can set the text when the count is changed)
Your answer
Follow this Question
Related Questions
Changing gameobject assigned to a variable from string 1 Answer
Quest Script Help 2 Answers
Level Button And Quit Button Android 2 Answers
Changing GameObject texture? 4 Answers
How to make text appear when moving next to an object? 3 Answers