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.
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.