Last active
December 14, 2015 03:28
-
-
Save NickDiMucci/5020964 to your computer and use it in GitHub Desktop.
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
private void obtainScreenBounds() { | |
float cameraToPlayerDistance = Mathf.Abs(Camera.mainCamera.transform.position.z - transform.position.z); | |
minScreenBounds = Camera.main.ScreenToWorldPoint(new Vector3(0, 0, cameraToPlayerDistance)); | |
maxScreenBounds = Camera.main.ScreenToWorldPoint(new Vector3(Screen.width, Screen.height, cameraToPlayerDistance)); | |
} | |
private void checkScreenBoundaries() { | |
transform.position = new Vector3( | |
Mathf.Clamp(transform.position.x, (minScreenBounds.x) + 1, (maxScreenBounds.x) - 1), | |
Mathf.Clamp(transform.position.y, (minScreenBounds.y) + 1, (maxScreenBounds.y) - 1), | |
transform.position.z); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment