Gui position

Hi,
How can I set gui position to object position?
I want every gui show on object surface.

GUI lives in 2D space in front of the world space. World objects are “anchored” at their pivot point. GUI objects are anchored in the upper left corner (since you specify a Rect for position. There are three steps:

  1. Convert from world space to screen space
  2. Convert from screen space to GUI space
  3. Adjust the anchor

The code will look something like:

var v3 = Camera.main.WorldToScreenPoint(objectToTrack.position);  // world to screen
v3.y = Screen.height - v3.y; // screen to gui

v3.x -= textureToDisplayWidth / 2.0;  // Adjust the anchor point
v3.y += textureToDisplayHeight / 2.0;

// Rect for use in a GUI call
var rect = Rect(v3.x, v3.y, textureToDisplayWidth, textureToDisplayHeight);

Have you checked this out?? http://wiki.unity3d.com/index.php/ObjectLabel

Kinda does the thing your asking. Maybe you can modify it.

Thanks