I’m trying to get my labels to stay above my objects but if I’m looking directly down or up at the object the text will be positioned too much below or above the object, same thing if I zoom the camera too far in and out. Also when attempting to attach this script to other objects the labels go all over the place and dont remain over the other objects correctly.
public Vector3 offset = Vector3.up;
public Vector3 screenPos;
void Update () {
screenPos = Camera.main.WorldToScreenPoint(transform.position + offset);
}
void OnGUI ()
{
GUI.Label(new Rect(screenPos.x - 40,screenPos.y,100,50),"test1", textStyle);
GUI.Label(new Rect(screenPos.x - 80,screenPos.y + 20,300,50),"test2test2test2", textStyle);
}