- Home /
Get 3D Text size
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!
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);
return bounds.IntersectRay(ray);
}
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 $$anonymous$$esh and Renderer components! Fortunately it is. Thanks anyway! :)
Your answer

Follow this Question
Related Questions
Destroy 3D text? 1 Answer
Problem with fonts with ttf format 2 Answers
3D Text Mesh - Display Glitch 0 Answers
i Have AN error when i create assets font editor 0 Answers
3D text timer 2 Answers