Last active
February 23, 2021 22:43
-
-
Save Enigo/d7a387e65eb158b41cbb0c756e3bbebf to your computer and use it in GitHub Desktop.
This file contains 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 void Awake() | |
{ | |
StartCoroutine(SetupInitialOrientation()); | |
} | |
private static IEnumerator SetupInitialOrientation() | |
{ | |
if (PlayerPrefsUtils.HasOrientation()) | |
{ | |
if (PlayerPrefsUtils.IsPortrait()) | |
{ | |
if (Screen.orientation != ScreenOrientation.Portrait) | |
{ | |
Screen.orientation = ScreenOrientation.Portrait; | |
yield return new WaitForSeconds(3); | |
LoadScene(); | |
} | |
} | |
else | |
{ | |
if (Screen.orientation != ScreenOrientation.Landscape) | |
{ | |
Screen.orientation = ScreenOrientation.Landscape; | |
yield return new WaitForSeconds(3); | |
LoadScene(); | |
} | |
} | |
yield break; | |
} | |
LoadScene(); | |
} | |
private static void LoadScene() | |
{ | |
SceneManager.LoadSceneAsync("SampleScene"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment