Monday, September 5, 2022
HomeGame Developmentunity - Does Display.orientation not work in simulator?

unity – Does Display.orientation not work in simulator?


This isn’t an issue with Display.orientation – you simply have a bug in your code.

This if situation:

if (    Display.orientation == ScreenOrientation.LandscapeLeft
     && Display.orientation == ScreenOrientation.LandscapeRight )

Says “If Display.orientation is concurrently each LandscapeLeft AND LandscapeRight…”

However clearly the telephone cannot be each laying to the left AND laying to the best on the similar time. Macroscopic objects like telephones do not get to occupy two contradictory states in superposition.

So this situation is inconceivable, and all the time evaluates to false, that means your else block is all the time the one which executes.

It seems like what you need right here is:

if (    Display.orientation == ScreenOrientation.LandscapeLeft
     || Display.orientation == ScreenOrientation.LandscapeRight )

That double-pipe || is “OR” not “AND”. So we’ll execute the primary block if the telephone is both mendacity to the left, OR mendacity to the best.

The else block will then set off provided that neither of these is true (ie. the telephone is standing vertically – upright or upside-down).

Make sure to proofread your code for typos like this. 90% of the time, while you encounter an issue that appears like “is that this engine utilized by hundreds of builders and profitable video games fully and totally damaged, or did I simply make a mistake someplace?” the reply is often that you simply made a mistake someplace.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments