Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Murphy · Mar 22, 2010 at 03:43 PM · graphicsproceduraltextmesh

Procedurally generate a TextMesh

I am trying to display 3d text in the world and TextMesh seems to be the way to go. Here is what I have so far:

var wallTxt = new GameObject("WallText");
wallTxt.AddComponent(TextMesh);
wallTxt.AddComponent(MeshRenderer);
wallTxt.GetComponent (TextMesh).text = "Hello World";
var myFont : Font = (Resources.Load("Courier") as Font);
wallTxt.GetComponent(TextMesh).font = myFont;
wallTxt.transform.position.y = 10;
GameObject.CreatePrimitive(PrimitiveType.Cube).transform.position.y = 10;

It displays something but the text is all black blocks instead of letters. Any ideas how to do this properly?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

7 Replies

· Add your reply
  • Sort: 
avatar image
7
Best Answer

Answer by Eric5h5 · Mar 22, 2010 at 07:04 PM

It's simpler if you create a prefab of a TextMesh, and then instantiate the prefab.

var textMeshPrefab : TextMesh;

function Start () { var wallTxt : TextMesh = Instantiate(textMeshPrefab, Vector3.up*10, Quaternion.identity); wallTxt.text = "Hello World"; }

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Murphy · Mar 22, 2010 at 09:48 PM 0
Share

Although not ideal this method does work. Thanks!

avatar image Barrett-Fox · Mar 28, 2011 at 11:58 PM 0
Share

0

The answer to this question is to instantiate a Text$$anonymous$$esh from a prefab. But is that the most elegant solution? I ran into the same roadblock when trying to build a Text$$anonymous$$esh dynamically from code. And I'm not finding any other answers.

Is there a reason why a dynamically generated Text$$anonymous$$esh does not have the same default material and font as one that you create in the editor?

avatar image
1

Answer by wrongkiddied · Aug 29, 2011 at 03:16 AM

You were on the right track. After some futzing I got this to work:

var wallTxt = new GameObject("TextField"); wallTxt.AddComponent(TextMesh); wallTxt.AddComponent(MeshRenderer); var meshRender: MeshRenderer = wallTxt.GetComponent(MeshRenderer); var material: Material = meshRender.material; meshRender.material = Resources.Load("Arial", Material); wallTxt.GetComponent (TextMesh).text = "Hello world"; var myFont : Font = Resources.Load("Arial",Font); wallTxt.GetComponent(TextMesh).font = myFont;

Just be sure to create a Resources folder in the Assets folder and put the font you want to load in there.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by forest j · Mar 22, 2010 at 06:34 PM

Try doing the same procedure in the editor and compare the result of your script with the working textmesh from the editor.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Reiv3r · Sep 24, 2011 at 11:11 PM

OLD ANSWER. But you need to attach the font material to the Mesh Renderer.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image timberland8989 · Sep 25, 2011 at 03:38 AM 0
Share

Thanks for co$$anonymous$$g our timberland online store! Just enjoy yourself here! As a developping company, timberland boots always can give us some surprise .I belive timberland shoes Sale can make your feet more comfortable, make your life more stylish!If you want to have a try ,just click here: discount timberland boots Free delivery

timberland

timberland boot

timberland shops

timberland 2011

discount timberland

wholesale timberland

timberland chaussures

avatar image
0

Answer by Reiv3r · Sep 24, 2011 at 11:11 PM

Old solution. You need to attach the font material to the Mesh Renderer you instantiate.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
  • 1
  • 2
  • ›

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Creating an outline around the opaque pixels on a plane. Outline should extend outside of plane. 0 Answers

Procedurally combine (merge) two Texture2D 2 Answers

Procedural Shader Cost/Draw Calls 1 Answer

How to make this low poly terrain look better 1 Answer

Asset store categories - How to determine best fit for my asset 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges