- Home /
Android: How do I force only portrait orientation?
The only setting I can find regarding orientation in the editor is in Player Settings, under Android, there is a Default Orientation option. But that doesn't prevent someone from rotating their device and having autorotate change the orientation of the game.
I thought there was an option somewhere to disable certain orientations? I'm having a hard time finding this, and searching here/google for a solution is surprisingly unhelpful. There is a lot of talk about changing the orientation via code and in xml manifests, but how do I do it in the editor?
Answer by Disastercake · Apr 29, 2015 at 07:50 PM
In Unity 5 I found the options for disabling different orientations under the Edit >> Project Settings >> Player.
Then under "Resolution and Presentation" group you can see the "Orientation" sub group, then you will find the relevant "Default Orientation" option. You can set it to Portrait from the dropdown menu here to force orientation.
This disabled the auto orientation, so rotating the phone around will not cause the orientation to change.
Hmm, the 4 checkboxes for the 4 orientations are there for quite some time now. I think even Unity 3.5 had them already.
Personally I hate when developers do this. You need to have a very good reason why you don't allow upside-down rotation. For example it wouldn't make sense to allow upside down in one of those pointless ibeer apps as it would actually break it's function / purpose.
I play all portrait games on my Nexus upside down because most the time i have the power cord attached at the bottom and it always get's in the way. I still be able to play any portrait game upside down by locking the rotation before i start the game, however i prefer when the app supports this (like subway surfers for example).
Just enable autorotate and restrict the orientations to portrait. If you have trouble that it doesn't rotate at start, simply set the orientation in Start() to the best fitting portrait orientation.
btw you can set all those things inside the Screen class from script. You might want to use Input.deviceOrientation to deter$$anonymous$$e how the user hold the device at startup. With a few lines of code you can get the perfect starting orientation ^^
This is STILL RELEVANT in Unity 2020.3.23f1.
Thank you for the solution.
Answer by lulitha · Jul 14, 2020 at 04:01 PM
how do i stop rotate only one scence?
You can just individually set autorotation for different orientations. Just set them to false when you load that scene and set them back to true when you unload it.
They're accessible as: - Screen.autorotateToLandscapeLeft - Screen.autorotateToLandscapeRight - Screen.autorotateToPortrait - Screen.autorotateToPortraitUpsideDown
Answer by Myron145 · Apr 29 at 12:11 PM
I want to use all activities in my form in landscape or portrait. When user select orientation - this is valid for all activities. Tried with "behind" option orientation. According to Google - orientation will depend on previous activity. DinarRecaps.com
My first activity use setRequestedOrientation to set selected from user orientation.
Next activities have to follow same orientation. Do I have to put setRequestedOrientation in their code too? Or really on 'behind' parameter in manifest? Putting setRequestedOrientation may be cause onCreate again?
UPDATE: Tried "portrait" and setRequestedOrientation() - result is onCreate was called 2 times.
Problem is in next activity -> because of "portrait" in first activity - android started next activity with same orientation. It ignores "landscape" orientation which was set by me.
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
Unity in iOS Tab Bar Controller Orientation Issue 0 Answers
How to make an in-game settings menu? 1 Answer
Reorient the construction worker 0 Answers