Forum Discussion

🚨 This forum is archived and read-only. To submit a forum post, please visit our new Developer Forum. 🚨
Anonymous's avatar
Anonymous
11 years ago

Display a variable with 3D Text

Hi,

i would like to display a variable in a 3D text like :

var score = 100;


I try with textmesh, but with no success.

Have you got a simple script in javascript ?

Thanks in advance.

6 Replies

Replies have been turned off for this discussion
  • There are a couple of ways you can do this.

    If you create a text mesh in the editor, then position it where you want it in front of your camera. Then make the 3d Text mesh a child of the right camera.

    To reference it with 'TextMesh'. So you could for example do

    "public TextMesh tm", or "[Serializable Field] private TextMesh tm".

    Then just do:

    tm.text = score;

    whenever you need to update the score
  • Anonymous's avatar
    Anonymous
    Thanks you, i'll try this asap !
  • No worries. Also I just realised I gave you a C# solution.

    I think the javascript alternative is "@SerializeField private var tm:TextMesh"
  • Anonymous's avatar
    Anonymous
    Hi, i try this but no effect :

    I create a 3D text with by default text value "hello world".

    Then i do this script :

    @SerializeField private var tm:TextMesh;
    var score = 100;

    function Update () {
    tm.text = score;
    }


    But the text stay "hello world" instead of the value of my variable score : 100.

    Any idea ? thanks !
  • In the actual editor, did you remember to 'drag' your 3D text mesh into your script?

    If you look at your script in the editor, it should show your variable 'Tm' with the phrase "None (Text Mesh") next to it. Just drag your 3dTextMesh into that area and you should be good to go.

    Like I said this is one way of accessing your 3d Text Mesh component. This will at least get things working.

    Hope this helps
  • Anonymous's avatar
    Anonymous
    It's OK , i drag 3d text in the tm area.

    Thanks a lot !