Skip to content

Instantly share code, notes, and snippets.

@Enigo
Last active February 23, 2021 22:43
Show Gist options
  • Save Enigo/d7a387e65eb158b41cbb0c756e3bbebf to your computer and use it in GitHub Desktop.
Save Enigo/d7a387e65eb158b41cbb0c756e3bbebf to your computer and use it in GitHub Desktop.
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