Last active
February 23, 2021 22:39
-
-
Save Enigo/1797e65f74cf12e8533a2a94b7bef601 to your computer and use it in GitHub Desktop.
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
public class OrientationSetter : MonoBehaviour | |
{ | |
private static IEnumerator SetupInitialOrientation() | |
{ | |
if (PlayerPrefsUtils.HasOrientation()) | |
{ | |
if (PlayerPrefsUtils.IsPortrait()) | |
{ | |
SetupPortraitOrientation(); | |
if (Screen.orientation != ScreenOrientation.Portrait) | |
{ | |
Screen.orientation = ScreenOrientation.Portrait; | |
yield return new WaitForSeconds(3); | |
LoadScene(); | |
} | |
} | |
else | |
{ | |
SetupLandscapeOrientation(); | |
if (Screen.orientation != ScreenOrientation.Landscape) | |
{ | |
Screen.orientation = ScreenOrientation.Landscape; | |
yield return new WaitForSeconds(3); | |
LoadScene(); | |
} | |
} | |
yield break; | |
} | |
if (Screen.orientation == ScreenOrientation.Portrait) | |
{ | |
SetupPortraitOrientation(); | |
} | |
else | |
{ | |
SetupLandscapeOrientation(); | |
} | |
LoadScene(); | |
} | |
private static void SetupPortraitOrientation() | |
{ | |
Screen.autorotateToPortrait = true; | |
Screen.autorotateToPortraitUpsideDown = true; | |
Screen.autorotateToLandscapeLeft = false; | |
Screen.autorotateToLandscapeRight = false; | |
} | |
private static void SetupLandscapeOrientation() | |
{ | |
Screen.autorotateToPortrait = false; | |
Screen.autorotateToPortraitUpsideDown = false; | |
Screen.autorotateToLandscapeLeft = true; | |
Screen.autorotateToLandscapeRight = true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment