Skip to content

Instantly share code, notes, and snippets.

@umuralpay
Last active March 14, 2020 18:49
Show Gist options
  • Save umuralpay/9e8ca70a0ba9b688f7bc1a3371a95440 to your computer and use it in GitHub Desktop.
Save umuralpay/9e8ca70a0ba9b688f7bc1a3371a95440 to your computer and use it in GitHub Desktop.
Unity Ortographic Width And Height
// Height
float orthoSize = gameField.bounds.size.y / 2;
// Width
float orthoSize = gameField.bounds.size.x * Screen.height / Screen.width * 0.5f;
Camera.main.orthographicSize = orthoSize;
//See All
float screenRatio = (float)Screen.width / (float)Screen.height;
float targetRatio = gameField.bounds.size.x / gameField.bounds.size.y;
if(screenRatio >= targetRatio)
{
Camera.main.orthographicSize = gameField.bounds.size.y / 2;
}
else
{
float differenceInSize = targetRatio / screenRatio;
Camera.main.orthographicSize = gameField.bounds.size.y / 2 * differenceInSize;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment