Skip to content

Instantly share code, notes, and snippets.

@sdabet
Created January 21, 2015 12:56
Show Gist options
  • Save sdabet/bd5bea17811066f0d934 to your computer and use it in GitHub Desktop.
Save sdabet/bd5bea17811066f0d934 to your computer and use it in GitHub Desktop.
Aspect ratio script for Unity
using UnityEngine;
using System.Collections;
public class AspectRatioScript : MonoBehaviour {
public float targetAspect;
void Start ()
{
float windowAspect = (float)Screen.width / (float)Screen.height;
float scaleHeight = windowAspect / targetAspect;
Camera camera = GetComponent<Camera>();
if (scaleHeight < 1.0f)
{
camera.orthographicSize = camera.orthographicSize / scaleHeight;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment