Skip to content

Instantly share code, notes, and snippets.

View NickDiMucci's full-sized avatar

Nicholas DiMucci NickDiMucci

View GitHub Profile
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),