Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
0
Question by Sephius · Jul 13, 2013 at 03:43 AM · c#fonttextmesh

Create a 3d text using c# (font problem)

Hello there !

I am trying to create a 3d Text using c#, but i have trouble with the fact that instead of text, it displays a pink square. The problem, in my opinion, is that it doesn't have any texture, because it doesn't have any font. Here is the code :

         GOTroopsCountIn = new GameObject("TroopsCount");
         GOTroopsCountIn.AddComponent("TextMesh");
         GOTroopsCountIn.AddComponent("MeshRenderer");
         TextMesh TMTroopsCountIn = (TextMesh) GOTroopsCountIn.GetComponent("TextMesh");
         TMTroopsCountIn.font = ??????????? ;


So here is my question : how can i find a font to assignate it to my TextMesh (using c#) ? (The default font, Arial)

Have a nice day !

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

2 Replies

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

Answer by robertbu · Jul 13, 2013 at 06:52 AM

The pink squares are what you get when you don't have a material assigned, or if your shader has errors. I use EZGUI rather than TextMesh, so I had to play a bit to get something to work.

I dragged and dropped a TTF font into the project. In order to get the letters to appear on the texture associated with the font, I had to change the font import settings 'Character' property to 'Unicode'. Then I followed the instructions here to create a shader and material:

http://wiki.unity3d.com/index.php?title=3DText

Next I attached the following script to an empty game object:

 var mat : Material;
 var font : Font;
 
 function Awake() {
     var Text = new GameObject();
  
     var textMesh = gameObject.AddComponent(TextMesh);
     textMesh.font = font;
     var meshRenderer = gameObject.AddComponent(MeshRenderer);
     meshRenderer.material = mat;
 
     textMesh.text = "Hello World!";
 }

I dragged and dropped the font and the material onto the public variables and hit play.

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 Sephius · Jul 13, 2013 at 11:30 PM 0
Share

Thank you for the answer :D

avatar image
0

Answer by shopguy · Sep 18, 2014 at 02:29 AM

This seems easier. No custom shader, unless you needed the shader for some other reason. A Font object includes Font.material, and when you add a TextMesh it includes the render, so you can skip some steps and just do:

 var font : Font;
  
 function Awake() {
    var Text = new GameObject();
    var textMesh = Text.AddComponent(TextMesh);
    textMesh.font = font;
    textMesh.GetComponent<Renderer>().material = font.material;
    textMesh.text = "Hello World!";
 }
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 shopguy · May 30, 2015 at 10:31 PM 0
Share

Nice when you find your own answers a year later and they help you :) Anyway, just updated for Unity 5, since text$$anonymous$$esh.renderer is depreciated now.

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

16 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

How do I access built in shaders and fonts? 1 Answer

Distribute terrain in zones 3 Answers

How to access a Text Mesh Pro Font Asset's glyp info from c#? 1 Answer

TextMesh is not rendering Font correctly 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