Skip to content

Instantly share code, notes, and snippets.

@NickDiMucci
Last active December 14, 2015 03:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NickDiMucci/5020964 to your computer and use it in GitHub Desktop.
Save NickDiMucci/5020964 to your computer and use it in GitHub Desktop.
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