- Home /
How to draw 3D text from code
Hey guys,
I was wondering, how can you draw 3D text from code???
Thanks
-Grady
Retagged 3d, text to 3dtext and textmesh. Greetz, $$anonymous$$y.
Answer by LegionIsTaken · Jul 05, 2011 at 09:04 AM
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. :)
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 -> $$anonymous$$esh -> Text $$anonymous$$esh 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????
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?
Yes, you can enable and disable the $$anonymous$$eshRenderer that is also attached to the GameObject. textGameObject.GetComponent("$$anonymous$$eshRenderer").enabled = false
.
O$$anonymous$$, 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
Answer by Marnix · Jul 03, 2011 at 10:27 AM
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.
@Grady Updated my answer. Hope this will help you further.
what do i put in "the text" variable? is that supposed to be a premade 3d text or something????
I think you also need to add a meshrenderer. As you can see in the Text$$anonymous$$esh link I provided. Will update my answer.
i keep getting the following error in the console: "ArgumentException: You are not allowed to call Internal_CreateGameObject when declaring a variable. $$anonymous$$ove it to the line after without a variable declaration."
I'm not sure what I've done wrong...
-Grady
Answer by murl1845 · Dec 02, 2020 at 12:34 AM
You can generate 3D text from code in many ways .One of this is, you first create a prefab of the characters , give it as an input to the script and then generate 3D text from script by instantiating gameobjects.
I found this YouTube video helpful https://youtu.be/B7mi3pXl0GM
Your answer
Follow this Question
Related Questions
3D Text bug (text disappearing) 3 Answers
TextMesh update causing framerate drop 1 Answer
How to save 3d text 1 Answer
Updating LCD display? 1 Answer
How do you create genuine shadows from a Text Mesh? 1 Answer