Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Please give some advice about ScreenOrientation

Discussion in 'Scripting' started by Harardin, Dec 2, 2016.

  1. Harardin

    Harardin

    Joined:
    Aug 5, 2015
    Posts:
    58
    Hello everyone.

    I don’t have much of experience in working with Android and iOS devices.

    So I’am asking for advice

    If I want in some statement left Screen oriented only Portrait should it be like this?
    Code (CSharp):
    1.     void Update () {
    2.         if ("this true")
    3.         {
    4.             Screen.autorotateToPortrait = true;
    5.             Screen.autorotateToLandscapeLeft = false;
    6.             Screen.autorotateToLandscapeRight = false;
    7.             Screen.autorotateToPortraitUpsideDown = false;
    8.             Screen.orientation = ScreenOrientation.Portrait;
    9.         }
    10.         else if ("another condition when I want it to be left oriented and portrait")
    11.         {
    12.             Screen.autorotateToPortrait = true;
    13.             Screen.autorotateToLandscapeLeft = true;
    14.             Screen.autorotateToLandscapeRight = false;
    15.             Screen.autorotateToPortraitUpsideDown = false;
    16.             Screen.orientation = ScreenOrientation.AutoRotation;
    17.         }
    18.     }
    Will this work?
    Sorry if this is simple question but testing it via compilation is longer then ask some one.
    Thanks.
     
  2. Harardin

    Harardin

    Joined:
    Aug 5, 2015
    Posts:
    58
    Yeap it will work.