Created
January 21, 2015 12:56
-
-
Save sdabet/bd5bea17811066f0d934 to your computer and use it in GitHub Desktop.
Aspect ratio script for Unity
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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