Skip to content

Instantly share code, notes, and snippets.

@utoxin
Last active February 13, 2020 15:54
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 utoxin/9ce26afd0b90fc2fd9d7c3c18ba4ce3b to your computer and use it in GitHub Desktop.
Save utoxin/9ce26afd0b90fc2fd9d7c3c18ba4ce3b to your computer and use it in GitHub Desktop.
Sets the Orthographic Size of the main camera to make sure that the play area stays in view. The min vertical and horizontal units are relative to the center of the screen, the same as the Orthographic Size value.
class OrthoAspectFixer : MonoBehavior {
private Camera _mainCamera;
public int minVerticalUnits;
public int minHorizontalUnits;
void Start() {
this._mainCamera = Camera.main;
}
void Update() {
this._mainCamera.orthographicSize = Math.Max(this.minVerticalUnits, this.minHorizontalUnits / this._mainCamera.aspect);
}
}
class OrthoAspectFixer : MonoBehavior {
public int minVerticalUnits;
public int minHorizontalUnits;
void Start() {
var mainCamera = Camera.main;
mainCamera.orthographicSize = Math.Max(this.minVerticalUnits, this.minHorizontalUnits / mainCamera.aspect);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment