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!

more ▼

asked Jun 30, 2010 at 08:34 AM

avatar image

55 6 4 13

Interesting question. I hope you get an answer!

Jun 30, 2010 at 09:52 AM Case23
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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.

more ▼

answered Aug 23, 2010 at 09:20 AM

avatar image

Scott Kerr
46 1 1 5

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! :)

Aug 27, 2010 at 08:55 AM dletozeun
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments



asked: Jun 30, 2010 at 08:34 AM

Seen: 4684 times

Last Updated: Jun 30, 2010 at 08:34 AM