Get current autorotation?

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?

It’s dependent what you using to autorotation? Maybe enough:

int time = 0;

if(Input.GetKey(KeyCode.Esc))
{
   time = (time == 0 ? 1 : 0); // 0 to paused, 1 to resaume
   Time.timeScale = time;
}

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.

So you don’t want autorotete some object on scene?! You thinking about autorotate screen … ok.
Use Screen.orientation:

Do you know how do this?

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.