Ghost Gaming
Ghost Gaming

Reputation: 55

How to change Unity2D aspect ratio with scenes?

I have multiple scenes in my mobile phone, in one scene the aspect ratio must be 16:10(vertical), in other scene it must be horizontal. I set the aspect ratio via Unity's GUI, but when I do this, the other scene is 16:10 too. Is there a way where I can change the aspect ratio, from the code? When that scene is loaded, the aspect ratio changes.

Upvotes: 0

Views: 1754

Answers (2)

Ghost Gaming
Ghost Gaming

Reputation: 55

Screen.orientation = ScreenOrientation.LandscapeLeft;

Screen.orientation = ScreenOrientation.Portrait;

With these two codes I did, what I want to do. If the scene is playable horizontal, I used the first code, and for vertical, I used the second code. It worked like a charm

Upvotes: 0

Koshux
Koshux

Reputation: 346

So what you want to do is:

First go to this Unity Docs link and understand the use of canvas scaler and the options provided. Basically you can set the UI Scale Mode to Scale with Screen Size and set the resolution required. In my case I set it to 1920x1080 (see image below) so that each screen has the same resolution across scenes. Note that this must be applied to every canvas within the scenes.


Canvas Scaler example


This will allow you to configure any specific aspect ratio in terms of resolution across different scenes, as required. I hope this helps.

Upvotes: 1

Related Questions