I’m trying to create a game that is a top-down scrolling racer. Because it’s top down and not side-view, gravity isn’t a factor and the game should work fine in both landscape and portrait mode.
I want to enable that option and essentially have the game run the same way in both modes, but have the UI rotate according to the orientation.
The problem I’m having is that all my code was written using the assumption that the game would only be either landscape or portrait, which means that things don’t rotate like they should when I change orientation. This is because obviously when you rotate the screen, things like positive X ALWAYS face towards the right side of the screen. In order to support both orientations, I’d need a way to tell Unity that positive X should now be the top of the screen instead (i.e. flipping from landscape to portrait).
Some things I was considering were asking the native device OS what orientation we were in, and then if we detected a change to portrait mode, actually set the Screen.Orientation property in Unity back to landscape so the positive X is preserved. Then manually rotate the UI to work for portrait.
That sounds pretty hacky though. Short of coding all my logic to support different axes, what are some strategies people have used to accomplish this kind of thing?
Illustration: