Skip to content

Instantly share code, notes, and snippets.

@danhanfry
Created August 30, 2016 11:49
Show Gist options
  • Save danhanfry/2ca17bb16affcbc36ba955949aa0c75a to your computer and use it in GitHub Desktop.
Save danhanfry/2ca17bb16affcbc36ba955949aa0c75a to your computer and use it in GitHub Desktop.
Dictionary<float, float> ratiosList = new Dictionary<float, float>();
List<float> list = new List<float> { 1.78f, 1.67f, 1.33f, 1.6f, 1.5f, 1f };
void Awake () {
ratiosList.Add(1.78f, 5.4015f);
ratiosList.Add(1.67f, 5.7623f);
ratiosList.Add(1.33f, 7.1958f);
ratiosList.Add(1.6f, 6f);
ratiosList.Add(1.5f, 6.4f);
ratiosList.Add(1f, 2f);
float ratio = (float)Screen.width / (float)Screen.height;
ratio = Mathf.Round(ratio * 100f) / 100f;
float closest = list.Aggregate((x,y) => Mathf.Abs(x-ratio) < Mathf.Abs(y-ratio) ? x : y);
float cameraSize = ratiosList[closest];
this.GetComponent<Camera>().orthographicSize = cameraSize;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment