- Home /
update 3d text through script
I have the following script which is attached to a 3D Text object, but the text never gets updated. I call this function from another script that's why i have it as static. I have put in debug statements before and after the text line below and confirmed that it does get executed, however the 3D Text object doesn't show the value of InitBlocks.timetobreakallBoards in the 3D Text object. What am I doing wrong? thanks
static function PresentTime () {
text = "Time: " + InitBlocks.timetobreakallBoards;
}
Answer by cozmoziz · Feb 06, 2011 at 07:29 PM
nvm, used the following to set a reference to the component and then a .text to access the text of the 3D Text. I also had to move this code back to another script that was attached to the original object. If I had this code in a script that was attached to the 3D Text object then it didn't work.
var tm = GameObject.Find("3DTextObject");
(tm.GetComponent(TextMesh) as TextMesh).text = "Time: " + InitBlocks.timetobreakallBoards;
Answer by SarperS · Feb 06, 2011 at 07:32 PM
Here, not tested though it should work
var textMesh:TextMesh;
function Start(){ textMesh = gameObject.GetComponent(TextMesh); }
static function PresentTime () { text = "Time: " + InitBlocks.timetobreakallBoards; textMesh.text = text.ToString(); }
Your answer
![](https://koobas.hobune.stream/wayback/20220613103107im_/https://answers.unity.com/themes/thub/images/avi.jpg)