GUI Label on GameObject Problem

Hi,

I’m trying to overlay GUI labels on a Unity gameobject, say a cube.

I am using the following:

Vector3 ScreenPos = Camera.main.WorldToScreenPoint(new Vector3(transform.position);
GUI.Label(new Rect((float)ScreenPos.x, (float)(Screen.height - ScreenPos.y), 100, 20), “1”);

This appears to work fine as long as the camera is directly infront of the cube, when i move the camera to the side the label moves away from where it should be. If i change projection on the camera to orthographic it works so i am assuming I need to do something extra for unity to allow this to work in perspective view?

Has anyone seen an issue like this or can somebody point me in the right direction?

Well, you can use a 3D Text and parent it on the gameobject you want to overlay and make it disabled when you don’t want to overlay the label on the gameobject. Hope it helps…