x


How to draw 3D text from code

Hey guys,

I was wondering, how can you draw 3D text from code???

Thanks

-Grady

more ▼

asked Jul 03 '11 at 10:24 AM

Grady gravatar image

Grady
1.1k 66 70 82

Retagged 3d, text to 3dtext and textmesh. Greetz, Ky.

Jul 15 '11 at 01:32 AM SisterKy
(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first

You can also do this:

var TEXT : Textmesh; // Drag your 3d text here in the inspector.

function Update ()
{
TEXT.text = "I just answered your question! I hope this helps";
}

Done. :)

more ▼

answered Jul 05 '11 at 09:04 AM

LegionIsTaken gravatar image

LegionIsTaken
452 24 30 34

This is not "from code" =)

Jul 05 '11 at 09:15 AM Marnix

just to clear this up from both examples, what i am meant to do is create an empty game object in the hierarchy, and then attach Component -> Mesh -> Text Mesh to it. Then drag that into the variable????? because in Legion's example, that's what i did, but nothing came up, for Legion's example, am I actually supposed to create a 3D text game object in the hierarchy????

Jul 05 '11 at 10:03 AM Grady

ok, with Legion's example, i managed to get the script to work with a 3d text object, but i need the text to appear and then dissapear within another script, so say when the user presses a button, then it should appear, and then when they press it again, then it dissapears....

and also, is it possible to make the text appear at any place within the scene from the script?

Jul 05 '11 at 10:06 AM Grady

Yes, you can enable and disable the MeshRenderer that is also attached to the GameObject. textGameObject.GetComponent("MeshRenderer").enabled = false.

Jul 05 '11 at 10:17 AM Marnix

OK, I'm using Legion's example, but what do I do? considering you both helped just as much.... I don't know who to give the right answer to... unless you guys want me to vote up both your answers or something.... :P

Jul 05 '11 at 10:37 AM Grady
(comments are locked)
10|3000 characters needed characters left

Use a TextMesh. There is also a script reference, which should definitely help you to create the text you are looking for.

Update
To create this in code, you can just add a component to your empty GameObject.

//somewhere in some manager object
function Awake()
{
    var theText = new GameObject();

    var textMesh = theText.AddComponent("TextMesh");
    var meshRenderer = theText.AddComponent("MeshRenderer");

    // do some settings here that are needed in the component
    // set the text
    textMesh.text = "Hello World!";
}

It depends if you need to set a font or not, because I don't know if there is a default one. Please check that in your Hierarchy.

more ▼

answered Jul 03 '11 at 10:27 AM

Marnix gravatar image

Marnix
1.3k 21 31 45

So do I make the 3d text in the heirarchy first?

Jul 03 '11 at 10:36 AM Grady

@Grady Updated my answer. Hope this will help you further.

Jul 03 '11 at 10:48 AM Marnix

what do i put in "the text" variable? is that supposed to be a premade 3d text or something????

Jul 03 '11 at 11:39 PM Grady

I think you also need to add a meshrenderer. As you can see in the TextMesh link I provided. Will update my answer.

Jul 04 '11 at 09:09 AM Marnix

i keep getting the following error in the console: "ArgumentException: You are not allowed to call Internal_CreateGameObject when declaring a variable. Move it to the line after without a variable declaration."

I'm not sure what I've done wrong...

-Grady

Jul 04 '11 at 11:04 PM Grady
(comments are locked)
10|3000 characters needed characters left

Where Do You Go

more ▼

answered Oct 06 '12 at 02:02 PM

1099 gravatar image

1099
1

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x534
x103
x101
x100

asked: Jul 03 '11 at 10:24 AM

Seen: 5937 times

Last Updated: Oct 06 '12 at 02:02 PM