Created
January 10, 2023 16:24
-
-
Save syl3n7/f0c35b0a6603daca5e2469898c0a568e to your computer and use it in GitHub Desktop.
redimension unity screen / canvas with 9:16 proportions
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 System; | |
using UnityEngine; | |
using UnityEngine.UI; | |
public class Redimension : MonoBehaviour | |
{ | |
private float lastWidth; | |
private float lastHeight; | |
void Start() | |
{ | |
Screen.SetResolution(1080, 1920, false, 60); | |
} | |
void Update() | |
{ | |
SetRatio(9, 16); | |
} | |
void SetRatio(float w, float h) //function to set the ratio of the screen to maintain the aspect of the resolution asked by the teacher (1080x1920) | |
{ | |
if ((((float)Screen.width) / ((float)Screen.height)) > w / h) | |
{ | |
Screen.SetResolution((int)(((float)Screen.height) * (w / h)), Screen.height, false); | |
} | |
else | |
{ | |
Screen.SetResolution(Screen.width, (int)(((float)Screen.width) * (h / w)), false); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment