Making a GUIText stay on the middle of an object

Hi guys,

I am trying to make a box with some text in it, and it works fine,
but whenever I move the camera arround, the text won’t follow, even through the text is attached to the textbox (and the textbox is attached to the camera).

But it still won’t follow the camera. Do you have any hints how I could achive a “cam following text” ?

If the GUIText is tracking a real 3D box, then you have to translate the box xyz in meters to the screen using WorldToViewPortPoint, with no childing.

GUIText’s are placed in ViewPort coords, which are screen 0-1 numbers. So if your box is in the center of the screen, as real world x=59 meters, the GUIText should have x=0.5 screens (1/2-way.) If the box moves to x=65 meters, the GUIText might move to x=0.6 screens (depending on camera position.) Or it might move to x=0.1 screens if you’re looking the other way and are closer. Or it will stay at 0.5 if you’re looking sideways at it (the box is getting closer.) So, childing just won’t work.

The math is, each frame run: theGuiText.position = Camera.main.WorldToViewPortPoint(targetCube.position);

That will also draw the GUIText if the box is directly behind you, but there are answers here about testing for -z (a box exactly behind you and far away will be at (-0.5, -0.5, -50)