I’m looking at all the search results for “orientation” in the docs and getting confused.
I want my game to be playable on an iPad any way you turn it.
Is there any reason why Screen.orientation and Input.deviceOrientation would not agree if I have it set to auto-rotate?
Screen.orientation is the logical screen orientation affected by screen auto-rotate setting and device orientation lock.
Input.deviceOrientation is the orientation of the actual device. When auto-rotate is enabled, Screen.orientation will be AutoRotation while Input.deviceOrientation may be FaceUp or FaceDown, or any of the other enumeration members:
Having AutoRotation in ScreenOrientation enumeration is a little confusing. Until ScreenOrientation reflects the actual screen orientation, you may want to create a state machine that tracks changes in screen orientation.
Screen.orientation is where you forcibly set the orientation not get it
I haven’t been able to locate any documentation about it, but in a MonoBehaviour you can implement a callback method to get notified when a RectTransform attached to the same game object changes dimensions. E g:
private void OnRectTransformDimensionsChange()
{
this.isPortrait = Screen.currentResolution.width < Screen.currentResolution.height;
}
This will avoid doing a busy wait in the update loop or a coroutine.