Hi there, I got a small problem:
In my game, I need to know the orientation of the device (though it should not autorotate etc, just read access).
I am trying to access it via :
Screen.orientation
I am testing this with Unity Remote und Unity 4.3., but
print(Screen.orientation);
only gives me: “Portrait”. (even if I explicitly set the Player Settings to landscape only).
The Player Settings are already configured (Auto-Rotation enabled, all 4 orientations enabled).
I suppose Unity Remote does not work properly, but I have to use it for testing purposes.
Anyone got an idea?
Thanks in advance and greetings!
you can show it in a GUI label intead of console, and then you put your apk in you device and the test it .
The Unity Remote app is very limited since it’s “just” a remote control for the Unity Editor. A lot things work differently on the actual device.
Besides that Screen.orientation just let you get / set the orientation of the (virtual) screen. To get the orientation of the device you should use Input.deviceOrientation as the screen in the editor can’t be rotated.
so i was just wanting a quick easy way to view how my project might look based on orientation in the Unity editor before i built my project.
i came up with this method hack to still be able to get the desired results in the editor…
public ScreenOrientation myScreenOrientation {
get{
#if UNITY_EDITOR
if(Screen.height > Screen.width){
return ScreenOrientation.Portrait;
} else {
return ScreenOrientation.Landscape;
}
#else
return Screen.orientation;
#endif
}
}
then instead of using Screen.orientation
i use myScreenOrientation
I did not do this for Input.deviceOrientation
because this may not be the same as what the screen orientation is… for example they could be laying in a bed with the phone overhead and it would read as facedown which is nether landscape or portrait and did not help me with my ui layouts