- Home /
How to test Screen Orientation?
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!
Answer by Bunny83 · Mar 31, 2014 at 05:07 PM
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.
@Avestas:
Could you tick the answer as solution so the question is marked as solved?
Input.deviceOrientation is nice, but the problem is that it also shows results like FaceUp, FaceDown etc. . This is not helpful if I like to check if the screen is LandscapeLeft or LendscapeRight, if my tablet for example lay's flat on the table.
@DiebeImDunkeln: If the tablet lies flat on the table, how should the tablet know where you are relative to the tablet? You could sit:
at the bottom (in which case you'd expect it to be in Portrait)
at the right side (-> LandscapeRight)
at the top side (-> PortraitUpsideDown)
at the left side (-> LandscapeLeft)
Those 4 situations are possible when the tablet lies flat on the table. If you (the person) walk around the table where the tablet sits, how should the tablet know where you are at the time?
The tablet uses the acceleration sensor (and it senses the gravitational pull of the earth) to setup a reference frame in the world. All it knows from that information is where "down" is. Based on that information it can deter$$anonymous$$e those 6 (+1) device orientations in the world:
$$anonymous$$ (in case no acc sensor is available)
Portrait (gravity pulls to the bottom)
PortraitUpsideDown (gravity pulls to the top)
LandscapeLeft (gravity pulls to the left side)
LandscapeRight (gravity pulls to the bottom)
FaceUp (gravity pulls to the back side)
FaceDown (gravity pulls to the front side)
Even if the device has a gyroscope, it wouldn't make much sense to return an orientation towards "north" or something like that since you're probably not in the "north direction" of the device.
in my case I solved the orientation problem with a switch orientation button which is visible on all screens.
You can click it and switch between LandscapeLeft and LandScapeRight. In out game it makes no sense to offer portrait mode.
We have 2-6 players who sit around the tables which lay's on the table. It's a round based board game with arcade $$anonymous$$i games. The $$anonymous$$i games are the reason why we don't offer portrait mode.
Answer by ava4414 · Mar 30, 2014 at 07:47 PM
you can show it in a GUI label intead of console, and then you put your apk in you device and the test it .
http://docs.unity3d.com/Documentation/ScriptReference/GUI.Label.html
Well, the problem is, I do not have an Apple $$anonymous$$ccount (yet). That's why I can't test it on the actual device :S
Any other suggestions?
But thanks anyway!
Answer by CrandellWS · Feb 25, 2021 at 08:30 PM
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
Your answer
Follow this Question
Related Questions
How do I change orientation without reorienting? 0 Answers
Unity Remote and Screen Orientation 2 Answers
How to have a scene rotate with the device orientation 0 Answers
l want my game object to appear in a location and change when screen size changes? 0 Answers
For mobile games, how could you divide the screen into three buttons vertically? 1 Answer