Last active
March 14, 2020 18:49
-
-
Save umuralpay/9e8ca70a0ba9b688f7bc1a3371a95440 to your computer and use it in GitHub Desktop.
Unity Ortographic Width And Height
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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