GUI location problem...

Hi. I am trying to have a GUI element appear directly above an object. But, when I try this, the “Hello World” label is nowhere near the object (it is somewhat random…sometimes its above the object, sometimes below, etc). What is wrong? Thanks.

function OnGUI () {
    GUI.Label (Rect (Camera.main.WorldToScreenPoint (transform.position).x, Camera.main.WorldToScreenPoint (transform.position).y, 100, 20), "Hello World!");
}

Well, you were pretty close ! The y is upside down. Try :

GUI.Label( Rect( Camera.main.WorldToScreenPoint (transform.position).x,
                 Screen.height - Camera.main.WorldToScreenPoint (transform.position).y,
                 100, 20),
          "Hello World!");

you might need to Camera.main.WorldToScreenPoint (transform.position).y + distance .

you might need to Camera.main.WorldToScreenPoint (transform.position).y + distance