How to handle runtime device rotations
I am looking for an approach or possibly an asset that can automatically handle the situation of Unity running on a device, and that device being rotated. Now I realize that I can test for the device orientation using something like this, but this isn't my question:
if ( Input.deviceOrientation == DeviceOrientation.LandscapeLeft )
What I am really after is a way to create a UI based on a portrait or landscape orientation and have it automatically move when a orientation is detected so that I can support multiple resolutions and orientations for my game.
Is there a feature in Unity that can automatically handle resolution and orientations or an asset that I can use for my canvas? If not, I'll write an asset to do it.
Answer by Asgardr · Jun 30, 2016 at 09:11 PM
Using the Unity UI, by properly applying the concept of anchor points, it shouldn't matter if your game is in portrait or landscape mode, as it should be able to handle any and all resolutions.
Make sure to read through this
Landscape and portrait are just different resolutions. Nothing special. Using the code snippet you showed, you could do specific behaviour for either orientation if you want in scripts.
I guess I wasn't clear. I get what you are saying, but simply resizing the screen won't work, I need to rearrange things, rather than just move things based on an anchor. I have a large game control and side controls, and the side controls need to move someplace else to have room for the big control.
Then I'd say you should use a script to switch all elements between anchor points you've made. $$anonymous$$ake a set of landscape anchors, and a set of portrait anchors, and switch the elements between them.