Collider around GUI text

I’m making a simlpe word bazed game, and for that I’d like to have a collider around the words I’m displaying (I use GUItext for that).

I tried using a box collider, but I can’t seem to find a good way to automaticly set size of the collider to match size of the word.

Code I’ve tried so far:

void setCollider()
	BoxCollider boxCollider = (BoxCollider) gameObject.AddComponent (typeof (BoxCollider));
	boxCollider.isTrigger = true;
	boxX = 0.1f * (guiText.text.Length - 1);
	boxCollider.size = new Vector3(boxX, boxY, 1);

This function is called from the start() function. It doesn’t give consistent results.

You can use GUIText.GetScreenRect() to get the Screen/pixel size of the text. You then need to convert that size into world space. For a perspective camera, you’ll need to pick a distance in front of the camera since world size and world coordinates vary based on the distance from the camera. For an Orthographic camera, you can use the Orthographic.size to directly calculate the world size.