ScreentoWorld point help- rotation

Hello. The health bar is not sticking to just the gameobject’s position; it shows up again when the camera is rotated 360 degrees. What am I missing? Thank you

var screenPosition: Vector3 = Camera.main.WorldToScreenPoint(transform.position);
	
    //draw the background
    GUI.Box ( Rect (screenPosition.x , Screen.height - screenPosition.y - size.y , size.x, size.y), transform.root.name);
    // draw the filled-in part:
    GUI.Box ( Rect (screenPosition.x , Screen.height - screenPosition.y - size.y , size.x * barDisplay, size.y),"");

Check the ‘Z’ coordinate of the return value Camera.main.WorldToScreenPoint(). If it is less than 0, the position is behind the camera.

if (screenPosition.z > 0.0) {
     //draw the background
     GUI.Box ( Rect (screenPosition.x , Screen.height - screenPosition.y - size.y , size.x, size.y), transform.root.name);
     // draw the filled-in part:
     GUI.Box ( Rect (screenPosition.x , Screen.height - screenPosition.y - size.y , size.x * barDisplay, size.y),"");
}