• 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 paulaceccon · Oct 16, 2012 at 09:26 PM · rendererboundstext mesh

Text with fixed size in viewport

Hi, i'm trying to do my Text Mesh always have the same size in the viewport. However, somet$$anonymous$$ng weird is happening. The text size change all the time, with a strange behavior. It's get bigger and than smaller, repeatedly.

My code is t$$anonymous$$s:

 void Update()
 {
 
     TextMesh textMesh = _billboard.GetComponentInC$$anonymous$$ldren<TextMesh>();
     TextBackground textBcg =_billboard.GetComponentInC$$anonymous$$ldren<TextBackground>();
             
     if(textMesh)
     {
         _targetViewportHeight = 40;
         textMesh.fontSize = 40;
         Vector3 minProjPoint = _camera.GetComponent<Camera>().WorldToScreenPoint( textMesh.collider.bounds.min );
         Vector3 upperLeftCorner = new Vector3( textMesh.collider.bounds.min.x, textMesh.collider.bounds.max.y, textMesh.collider.bounds.max.z );
         Vector3 maxProjPoint = _camera.GetComponent<Camera>().WorldToScreenPoint( upperLeftCorner );
                 
         float scaleCorrection = _targetViewportHeight / Mathf.Abs( maxProjPoint.y - minProjPoint.y );
         _billboard.transform.localScale = new Vector3( scaleCorrection,    scaleCorrection, scaleCorrection );
     }
 }


T$$anonymous$$s is what I get from my code, in play mode.

alt text

The Text Mesh get bigger and then smaller, repeatedly. I don't know how to fix t$$anonymous$$s, or what I'm doing wrong.

What seems to me (via debug tests), is that changing the scale doesn't affect the bounds. Bounds are not been update. =S

Thanks for any help.

behavior.png (520.6 kB)
Comment
Add comment · Show 10
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 Eric5h5 · Oct 16, 2012 at 09:27 PM 0
Share

It would be simpler if you just used a GUIText object instead.

avatar image paulaceccon · Oct 16, 2012 at 09:30 PM 0
Share

Yeah, but, besides this, the text have to "follow" the camera, so I thought I have to use Text Mesh, so that the text would be into the world. Can I do this with GUI Text?

avatar image ThePunisher · Oct 16, 2012 at 09:45 PM 0
Share

Do you have a perspective scene? In other words, a 3d scene?

avatar image paulaceccon · Oct 16, 2012 at 09:46 PM 0
Share

Yes, it's a 3D scene.

avatar image Eric5h5 · Oct 16, 2012 at 09:57 PM 0
Share

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

Show more comments

1 Reply

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

Answer by paulaceccon · Oct 30, 2012 at 08:32 PM

Hi, I could do t$$anonymous$$s work with the following code:

 void Update ()
 {
 
     TextMesh textMesh = _billboard.GetComponentInC$$anonymous$$ldren<TextMesh>();
     TextBackground textBcg = _billboard.GetComponentInC$$anonymous$$ldren<TextBackground>();
             
     if(textMesh)
     {
         _targetViewportHeight = 40;
         Vector3 minProjPoint = _camera.GetComponent<Camera>().WorldToScreenPoint( textMesh.renderer.bounds.min );
         Vector3 upperLeftCorner = new Vector3( textMesh.renderer.bounds.min.x, 
                                         textMesh.renderer.bounds.max.y, 
                                         textMesh.renderer.bounds.max.z );
         Vector3 maxProjPoint = _camera.GetComponent<Camera>().WorldToScreenPoint( upperLeftCorner );
         
         float scaleCorrection = _targetViewportHeight / Mathf.Abs( (maxProjPoint.y - minProjPoint.y) );
                 
         _billboard.transform.localScale = new Vector3(_billboard.transform.localScale.x * scaleCorrection, _billboard.transform.localScale.y * scaleCorrection, _billboard.transform.localScale.z * scaleCorrection);
     
     }
 }
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 paulaceccon · Nov 22, 2012 at 11:44 AM 0
Share

In others words, the problem was at the last line, cause I was not considering the previous scale.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

11 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

Related Questions

Renderer.bounds.extenct.x; cant find bounds 0 Answers

How do I check if an object is completely visible? 4 Answers

Bounds larger than expected 1 Answer

"Mesh 'NormalCurveRendererMesh': abnormal mesh bounds..." error appears on editor... 0 Answers

Renderer Bounds 3 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