Get screen height in real world coordinates

Screen.height returns pixels, but I need real world coordinates. Is it possible to get those?

For an Orthographic camera, the orthographicSize is 1/2 the real-world screen height. For a perspective camera, the calculation depends on the distance from the camera, since the camera sees more the further the distance…just like your eyes. The equation for height at distance is:

Height = 2 * Tan(0.5 * field_of_view) * distance;

This works in 2D, I don’t know about 3D, but it should work using Vector3s:

Start by getting the world point of the top-right corner of the viewport (viewport space places (1,1) at the top-right corner):

    Vector2 topRightCorner = new Vector2(1, 1);
    Vector2 edgeVector = Camera.main.ViewportToWorldPoint(topRightCorner);

Now edgeVector has the co-ordinates for the upper-right corner of the screen. Because the centre of the screen is at (0,0) and the screen is always rectangular, the top-right corner is exactly 50% of the screen size away in both axes, so:

Screen height and width in world size:

   float height = edgeVector.y * 2;
   float width = edgeVector.x * 2;