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

Get current autorotation?

Discussion in 'iOS and tvOS' started by Carpet_Head, Nov 13, 2015.

  1. Carpet_Head

    Carpet_Head

    Joined:
    Nov 27, 2014
    Posts:
    254
    Hey,

    In my app I would like to be able to "pause" autorotation while the user does certain tasks that use the accelerometer, but then "resume" autorotation when they finish that task.

    I can't find a way to pause the autorotation.

    It would be really easy to do if I could just ask when the current Screen.orientation is which the device is autorotating, and then set it to that for the duration.

    Is there a way to do this?
     
  2. rchmiel

    rchmiel

    Joined:
    Apr 5, 2015
    Posts:
    49
    It's dependent what you using to autorotation? Maybe enough:
    Code (csharp):
    1. int time = 0;
    2.  
    3. if(Input.GetKey(KeyCode.Esc))
    4. {
    5.    time = (time == 0 ? 1 : 0); // 0 to paused, 1 to resaume
    6.    Time.timeScale = time;
    7. }
     
    Last edited: Nov 13, 2015
  3. Carpet_Head

    Carpet_Head

    Joined:
    Nov 27, 2014
    Posts:
    254
    I think you accidentally posted the wrong code there. It looks like a pause script.

    The perfect solution would do these things:

    When the app is first opened, it will open at the correct orientation immediately.

    It will autorotate using the standard iOS device parameters and delays.

    It will Autorotate using animated autorotation. (if possible).

    The device will hold its orientation when the autorotation is paused.

    The device will resume the original behaviour when the autorotation is unpaused.
     
  4. rchmiel

    rchmiel

    Joined:
    Apr 5, 2015
    Posts:
    49
  5. DWilliams

    DWilliams

    Joined:
    Jan 12, 2015
    Posts:
    63
    As rchmiel linked, the screen orientation setting is probably what you need. Set it to a specific orientation LandscapeLeft, LandscapeRight and it will hold that orientation. Once you want to allow auto rotation again you set it back to Autorotation.

    The trick is locking to the current orientation meaning you'd have to know the current orientation at any point that you may have a pause. I think Input.deviceOrientation will have that info, but I can't remember for sure off the top of my head. Also I think deviceOrientation can have faceup and facedown so you probably wouldn't be able to just check at the moment of pause and instead would have to keep track of the last valid (presumably landscapeleft/right, and portrait/upsidedown) orientation.