GUI Label follow an object?

So I’m working on a 3D Menu sort of thing but its in game so I would like it to move with the character in the sense a single label is connected to a certain part of the 3D Object.

So how would I go about finding the pixel offsets in 3D Space to 2D for GUI Text, buttons and labels. I know how to make GUI components but not find the position of the 3D Objects to 2D for the GUI.

You should use Camera.WorldToScreenPoint() it is a method that you can use to transform the position of your character to the respective point (in pixels) in the screen.

Check: http://unity3d.com/support/documentation/ScriptReference/Camera.WorldToScreenPoint.html

To convert a world point to the screen space, use WorldToScreenPoint:

var target: Transform; // drag the target object here
var rect = Rect(0,0,300,100);
var offset =  Vector2(0, 1.5); // height above the target position

function OnGUI(){
    var point = Camera.main.WorldToScreenPoint(target.position + offset);
    rect.x = point.x;
    rect.y = Screen.height - point.y - rect.height; // bottom left corner set to the 3D point
    GUI.Label(rect, target.name); // display its name, or other string
}

This is ok for the GUI system, which uses screen coordinates. If you want to use GUIText or GUITexture, you must find the point with WorldToViewportPoint, which returns x and y in the range 0…1 (viewport coordinates).

I’m a little unclear as to what you’re looking for, it sounds like you are trying to have a floating billboard above a 3D object in game?

If so just have a flat object as a child of that object and have the transform.rotation be set to that of the camera, this should make it always turn to face the camera and be readable. To interact with it you could have the camera RayCast out from the camera to the mouse position, if it hits that flat object it then executes whatever your intended menu item is.

Use This. It worked for me.