Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Get the viewport size of an orthographic camera in unity
public class BoundryFinder : MonoBehaviour
public float xMin, xMax, zMin, zMax;
void Start()
GameObject sceneCamObj = GameObject.Find( "Main Camera" );
Camera mainCam = sceneCamObj.GetComponent<Camera> ();
Transform camPos = mainCam.transform;
float vertExtent = mainCam.orthographicSize;
float horzExtent = vertExtent * Screen.width / Screen.height;
zMin = -vertExtent + camPos.position.z + 0.5f;
zMax = vertExtent + camPos.position.z - 0.5f;
xMin = -horzExtent + 0.5f;
xMax = horzExtent - 0.5f;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.