Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unity app with different screen orientations

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?

like image 848
Eduardo Coelho Avatar asked Apr 18 '26 10:04

Eduardo Coelho


1 Answers

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.

like image 93
Radu Diță Avatar answered Apr 20 '26 16:04

Radu Diță



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!