- Home /
Changing 3D text in update
Hello,
So i have a quick question, who can help me done this. I want to show 3D Text "Score: " and also with score i want to show a counter like this "Score: " + counter Ok so i have already done this Debug.Log("Score: "+i.ToString()); but now i want that same Debug.Log to show on the 3D Text and i just don0t know how :S What i am doing wrong or what ever. I have done it like this: TextMesh 3dtext; 3dtext.tex="Score: "+i.ToString(); But this is not working at all :S
Is ur variable 3dtext a public global one? Or just something u declare in ur function?
Answer by PouletFrit · May 27, 2014 at 03:26 PM
Attach a TextMesh Component to the GameObject containing the script if you haven't already done it
And change:
TextMesh 3dtext;
3dtext.tex="Score: "+i.ToString();
By:
TextMesh 3dtext = GetComponent<TextMesh>();
3dtext.text = "Score: " +i+ToString();
Answer by Nerevar · May 27, 2014 at 03:27 PM
Hello,
Simple example using TextMesh:
1)In Game Hierarchy , create 3D Text . the object is named New Text
2)drag and drop the following script (name it text3d) to this object
using UnityEngine;
using System.Collections;
public class text3d : MonoBehaviour
{
int counter = 0;
TextMesh text;
// Use this for initialization
void Start () {
text= gameObject.GetComponent("TextMesh") as TextMesh;
}
// Update is called once per frame
void Update () {
text.text = "Score: "+counter.ToString();
counter++;
}
}
3)Implement the script and change the setting of your 3D text to customize it :p
This worked for me updating an on screen count-down timer, thanks ... Ps. I needed to do it in 3D text ins$$anonymous$$d of GUI because I'm using VR/stereoscopic views.
Your answer
![](https://koobas.hobune.stream/wayback/20220613150012im_/https://answers.unity.com/themes/thub/images/avi.jpg)