I'd like to place a Label above a GameObject. To do this, it seems I need to convert the GameObjects worldspace coordinates to screenspace. Anyone have an example of doing this? Thanks!
I'm thinking it goes something like this...
Vector3 sp = camera.WorldToScreenPoint(transform.position);
???
Rect r = new Rect(???);
GUI.Label(r, "Hello World!");
In javascript:
var mainCam: Camera = Camera.main; //I always cache component variables used frequently.
OnGUI(){
screenLoc: Vector3 = mainCam.WorldToScreenPoint(transform.position);
GUI.Label (Rect(screenLoc.x-25,screenLoc.y-20,50,20),"My Tag");
That should give you a label 20 pixels above your object center and centered over it (50 pixels wide). If you want the label to be above the top of the object, use renderer.bounds (and then min/max or extends). A script that labels objects (for you to look at) in the wiki is HERE.