Skip to main content
October 12, 2014

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.
    This topic has been closed for replies.

    6 replies

    Up and Coming
    October 13, 2014
    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
    October 13, 2014
    Thanks you, i'll try this asap !
    Up and Coming
    October 13, 2014
    No worries. Also I just realised I gave you a C# solution.

    I think the javascript alternative is "@SerializeField private var tm:TextMesh"
    October 16, 2014
    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 !
    Up and Coming
    October 17, 2014
    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
    October 17, 2014
    It's OK , i drag 3d text in the tm area.

    Thanks a lot !