- Home /
Should I be checking Input.deviceOrientation, or Screen.orientation?
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?
Answer by $$anonymous$$ · Oct 09, 2013 at 09:19 PM
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:
http://docs.unity3d.com/Documentation/ScriptReference/DeviceOrientation.html
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.
Answer by HeliosDoubleSix · Aug 20, 2013 at 10:54 PM
Screen.orientation is where you forcibly set the orientation not get it
Answer by Tomashu · Jun 17, 2021 at 11:46 AM
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.