I have 2d gui text that I place over a 3d object in the world. Issue I'm having is keeping the text in the same location above the 3d object based on distance. Not sure what math I can use to keep the text in the same Y position no matter what distance away the object is? offsetY should calculate the distance
targetPosition = Camera.main.WorldToScreenPoint(new Vector3(target.transform.position.x, target.transform.position.y, target.transform.position.z));
float distance = Vector3.Distance(Camera.main.transform.position, this.transform.position);
float offsetY = 150.0f;
this.transform.position = new Vector3(targetPosition.x, targetPosition.y + offsetY, targetPosition.z);