Question

I'm developing a game that runs on both mobile phones and tablets. Currently I'm using only the Portrait orientation for all devices but the portrait orientation looks better on phones meanwhile landscape orientation looks better on tablets.

I set "Portrait" option in the Unity's Player Settings > Resolution and Presentation > Default Orientation but I would like to provide a landscape layout for tablets (without affecting phones).

How I can I do that? Is there any why to programmatically set the Screen orientation when the application starts?

Était-ce utile?

La solution

You can try Screen.Orientation

In the Start (or Awake) method of a MonoBehaviour that is added to the stage call:

Screen.Orientation = ScreenOrientation.LandscapeRight

Now you just need to check if the device is tablet or phone, I don't know any way out of the box to do this, but you can check the aspect ratio and base your decision on this.

You can check the aspect ratio by getting Screen.width and Screen.height.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top