Created
March 17, 2016 03:54
-
-
Save rdeeb/0c07916239f0f9ffeeb1 to your computer and use it in GitHub Desktop.
Get the viewport size of an orthographic camera in unity
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
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