look as well as options for setting the game to windowed or fullscreen. Saving those settings is also simple by utilizing the Unity Player Preferences system. too much from memory but this allowed me to have the window a specific resolution. When on the build interface click 'Player Settings. There will be nothing on the scene apart from the MainCamera with the Solid Color of your choice and OrientationSetter GameObject responsible for proper scene orientation configuration.I see no way to enforce a resolution in this aspect ratio and anything like 16:9 or other standard ratios throws off my pixel perfect camera and all hell breaks loose. We will create yet another scene before the Splash that is called PreSplash. The concept is rather simple - you are likely to have a first Splash scene where you set up all the services that require one-time initialization (think of AdManager or StoreManager). Let’s tackle both of those problems with one solution which I call PreSplash! Nevertheless, there is a feature and we need to support it properly. What if the device auto-rotation is activated? I’m curious to talk to people that have it activated in 2021 though. Wait, have you noticed that too? Transition is not smooth! Screen freezes for a few moments and it feels like a poor user experience.īeside that there is one more edge case that wasn’t taken care of yet. With that done, if a player previously selected an orientation different from the current one and now starts the game a scene will be changed accordingly. If you ever read any of my tutorials before, you will instantly recognize this static helper script: Otherwise you will end up disappointing your player by making him change it every session. Since we exposed orientation change as a button it should be stored and restored upon next startup. It’s time to start unveiling the edge cases of our dead simple implementation.įirst and the most obvious miss is an absence of setting saving. There are various workarounds on Unity forum, but, honestly speaking, all of them are far from perfect. On top of that Unity doesn’t provide an EventHandler for this “native” event. You might be wondering - why to have that button at all instead of relying on the Device orientation change event? Whilst it is possible to make use of that, doing so will complicate the project quite a lot as you would need to account that the orientation change might happen on each and every scene. In reality you don’t actually see those weird intermediate frames when the scene is frozen in the opposite mode for a few seconds.īasically, that’s it, we are done here! If you think that it is too good to be true read on to find various edge cases hiding within this simple process of orientation change. Note! It looks way better on a phone comparing to the GIF. Let’s set up our scene, we will add a couple of images and a button to change the orientation: Building two separate versions of each scene is a tedious process! For this tutorial we will have Portrait as the default mode. Even though, in extreme cases you might want to create either a dedicated UI layer per orientation or even the whole scene, I personally would advise against that due to increased coding and maintenance complexity. Scene preparationīefore you even add your first element on a scene you should decide which screen orientation will be the default one. There are three parts: Scene preparation, Coding and Edge cases.
#Unity pc build in portrait android
It is also worth mentioning that the project was tested on Android only.Īs always, project sources are available at GitHub, find the link at the end of the page. Like in my case, Zen Jigsaw needed support for Tablets right from the start but I could never find time (till last week) to implement it. This article assumes that your game IS suitable for both orientations.
#Unity pc build in portrait how to
In this tutorial I will show you how to add support for both screen modes, also revealing a few edge cases that you might not have thought of. Obviously, by doing that a significant share of devices is left out. Quite often developers choose to “ignore” the fact that there are two screen orientations available on the market - Portrait and Landscape, adding support for only one of them. Background Photos by Anni Roenkae from Pexels