How do I get the screen size in units? I am creating a grid of cubes. The indices of the for loops are used to determine the placement of the cubes. So I would get vectors like (0, 0, 0), (0, 1, 0) etc. I want to get the screen width in units so I could do the following: Total Width = Left and Right Borders (1 + 1 units) + n * spacing between cubes (0.2 units) + n * Cube width (1 unit). So instead of 1080 for the Android, I need something like 25 units. Also, this is a perspective Camera.
Thanks,
Syed
Its a complicated question. Screen size for perspective has as much to do with positioning and filed of view than anything else. I believe there is an inView() call. If x objects in view, then screen size is x perhaps.
I am trying this for now. Hope this works, given the Camera is 10 units in front of the cube grid. The rotation of the camera is (0, 0, 0) and the FOV is 60 which is the Unity default.
Vector3 worldDimensions = Camera.main.ScreenToWorldPoint(newVector3(Screen.width, Screen.height, 10));
Debug.Log("World Dimensions " + worldDimensions);
And how many cubes fit in the view? That would be your answer no?
1 Like
Correct. The n in the above equation gives me the cubes.
Thanks,
Syed