I’ve tried setting the GUI to transform.position.x transform.position.y of the object, but this doesn’t seem to work.
Is the GUI using a different coordinate system, and if so, how do I translate the object position for the GUI?
Thanks…
I’ve tried setting the GUI to transform.position.x transform.position.y of the object, but this doesn’t seem to work.
Is the GUI using a different coordinate system, and if so, how do I translate the object position for the GUI?
Thanks…
i did it like this where callsign is the networked players name: this is attached to the netplayer
function OnGUI()
{
var camera = Camera.main.transform;
cameraRelative = camera.InverseTransformPoint(transform.position);
visible=(cameraRelative.z > 0);
if(visible(transform.position.y>=(Terrain.activeTerrain.SampleHeight(transform.position)+Terrain.activeTerrain.transform.position.y)))
{
var pos=Camera.main.WorldToScreenPoint (transform.position+transform.up*1.5);
GUI.Box (Rect (pos.x-50, Screen.height-pos.y-10, 100, 20), CallSign);
}
}
Thanks… you and some posters in another thread got me on the right track.
This is what worked for me:
//locks gui text to objects position
//doesn't work perfectly unless orthographic camera chosen
var customGuiStyle : GUIStyle;
var screenPosition : Vector3;
var offsetX = 28; //try to correct x position
var offsetY = 20; //try to correct y position
function Update (){
screenPosition = Camera.main.WorldToScreenPoint(transform.position);
screenPosition.y = Screen.height - screenPosition.y;
}
function OnGUI (){
GUI.Label(Rect(screenPosition.x - offsetX, screenPosition.y - offsetY,
60, 50),"TEST",customGuiStyle);
}