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
1
Question by pitaman · Feb 25, 2011 at 08:44 PM · textcolliderstextmeshdynamic3dtext

Cannot get 3D Text/Text Mesh to wrap or a attached collider used as a button to scale based on word count.

I'm using 3D Text/Text Mesh in Unity3D for dynamically loading text, but cannot get the text to wrap or a collider attached to the 3D Text/Text Mesh to scale based on growing word count.

Comment
Add comment · Show 1
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 vigneshraj · Aug 05, 2014 at 11:55 AM 0
Share

Hi the text format works fine if the word length is kept $$anonymous$$imum. If we have word length greater and we keep on typing with out space it goes out of bounding box. please check typing with out leaving space. Help me hoe to break that and bring that it in to bounding box.

2 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by ellens · Jul 05, 2012 at 02:51 PM

I had the same problem. With textMesh.renderer.bounds.size I used the following method to create line breaks:

 function formatText(textToFormat : String, textObj : TextMesh , desiredWithOfMesh : float) : String {
 var words = textToFormat.Split(" "[0]);
 var newString = "";
 var testString = "";
 for (var i = 0; i < words.length; i++){
 testString = testString + words[i] + " ";
 textObj.text = testString;
 var textSize = textObj.renderer.bounds.size.x;
 if(textSize > desiredWithOfMesh) {
 testString = words[i] + " ";
 newString = newString + "\n" + words[i] + " ";
 } else {
 newString = newString + words[i] + " ";
 }
 }
 return newString;
 }
 
 

Call the method with:

 var myText = formatText(myTextString, myTextMeshObj, maxWidth)
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 SergeantBiscuits · Apr 24, 2013 at 09:29 AM 0
Share

This code is awesome! Thank you ellens!

I made a $$anonymous$$or adjustment to make it work for text$$anonymous$$eshes that are rotated or parented to other objects. This should work for any text$$anonymous$$esh, ever:

 function formatText( textToFormat : String, textObj : Text$$anonymous$$esh , desiredWidthOf$$anonymous$$esh : float ) : String
 {
     var words = textToFormat.Split(" "[0]);
     var newString = "";
     var testString = "";
     
     for (var i = 0; i < words.length; i++)
     {
         testString = testString + words[i] + " ";
         textObj.text = testString;
         
         var textRot = textObj.transform.rotation;
         textObj.transform.rotation = Quaternion.identity;
         var textSize = textObj.renderer.bounds.size.x;
         textObj.transform.rotation = textRot;
         
         if(textSize > desiredWidthOf$$anonymous$$esh)
         {
             testString = words[i] + " ";
             newString = newString + "\n" + words[i] + " ";
         }
         else
             newString = newString + words[i] + " ";
     }
     return newString;
 }


Also here is a slightly modified version, which I developed for my own purposes but may come in handy for others. With this, set your Text$$anonymous$$esh.text to whatever you want. Then, just call this function with the Text$$anonymous$$esh and the desired width:

 static function FormatText( textObj : Text$$anonymous$$esh , desiredWidthOf$$anonymous$$esh : float )
 {
     var words = textObj.text.Split(" "[0]);
     var newString = "";
     var testString = "";
     
     for (var i = 0; i < words.length; i++)
     {
         testString = testString + words[i] + " ";
         textObj.text = testString;
         
         var textRot = textObj.transform.rotation;
         textObj.transform.rotation = Quaternion.identity;
         var textSize = textObj.renderer.bounds.size.x;
         textObj.transform.rotation = textRot;
         
         if(textSize > desiredWidthOf$$anonymous$$esh)
         {
             testString = words[i] + " ";
             newString = newString + "\n" + words[i] + " ";
         }
         else
             newString = newString + words[i] + " ";
     }
     textObj.text = newString;
 }
avatar image vigneshraj · Aug 05, 2014 at 11:56 AM 0
Share

Hi the text format works fine if the word length is kept $$anonymous$$imum. If we have word length greater and we keep on typing with out space it goes out of bounding box. please check typing with out leaving space. Help me how to break that and bring that it in to bounding box.

avatar image
0

Answer by alienheretic 1 · Mar 23, 2011 at 11:04 PM

try this it works for me make sure you add a box collider to the text mesh

var text_mesh=transform.GetComponent(TextMesh);
collider.size.x= renderer.bounds.size.x * 4;
collider.size.y= renderer.bounds.size.y * 3;
collider.center=Vector3(-1.0,0.5,0.0);

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

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Text map problem with 3d text 1 Answer

TextMesh Pro visible in editor but not in game window. 2 Answers

int to string problem 4 Answers

Insert 3d text to the front face of a cube GameObject 0 Answers

How to change text on a TextMesh with a non-dynamic font on iOS? 2 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