AFAIK, there is no direct access to the world size of a Text Mesh as it is possible in a regular Mesh through the "bounds" object. It is not possible to compute it from vertices data neither as there is also, no access to mesh data.
Is there already something that I am missing?
I need this for 3D HUD resizing according to content. For the moment I use the GUIstyle.CalcSize to get the text size in pixels, then use a magic scale factor to get the text world size. But this factor seems to depend on the font and also font size. Get the bounds of the TextMesh would be infinitely more simple.
Any help (hack) would be greatly appreciated! Thanks!
Interesting question. I hope you get an answer!
Answer by Scott Kerr
Aug 23, 2010 at 09:20 AM
Hey, I know it's a bit late but I spent ages trying to figure this out too.
Eventually a found a way which while pretty hacky is the most elegant way I've found so far.
The Renderer component has a Bounds variable used for visibility culling which basically equates to a bounding box of the contents. You can use this to get the size of the TextMesh from the Renderer attached to the same object.
Here's some sample code of using it for raycasting:
public void MouseOver()
Bounds bounds = renderer.bounds;
Ray ray = camera.ScreenPointToRay(Input.mousePosition);
You can get the size of the text from the Bounds.size variable.
Yes I have finally figure it out too but forgot to update this question. I never realized that this information was duplicated in Mesh and Renderer components! Fortunately it is. Thanks anyway! :)
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
To help users navigate the site we have posted a user guide.
If you are a new user, check out our FAQ for more information.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
For troubleshooting common problems with Unity 5.x Editor (including Win 10).
Answers and Comments
No one has followed this question yet.
Add a 3D text imprint to an Object/Mesh, export as OBJ. Possible?
3D Interactive Text
Display Digits with 3D text
abit of a noobie question here
Can You Animate Main Menu Title?