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 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, something 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 this:

 void Update()
 {
 
     TextMesh textMesh = _billboard.GetComponentInChildren<TextMesh>();
     TextBackground textBcg =_billboard.GetComponentInChildren<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 );
     }
 }


This 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 this, 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 ins$$anonymous$$d.

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 $$anonymous$$esh, 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 this work with the following code:

 void Update ()
 {
 
     TextMesh textMesh = _billboard.GetComponentInChildren<TextMesh>();
     TextBackground textBcg = _billboard.GetComponentInChildren<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.

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

Placing a GameObject on top of another GameObject. 1 Answer

Changing two different objects renderer colour 1 Answer

Can't convert Bounds from world coordinates to local coordinates 6 Answers

Get right or left Vector2/3 out of renderer.bounds 0 Answers

Want to frame multiple objects in camera view using render bounds 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