Keeping screen width and scaling screen height for different screen resolutions

Hi guys,

I need my game to have a constant screen width for every mobile device in the market. For this I need to scale the screen height in order to keep the same screen width, even though the screen ratio varies.

Here you have an example:

24901-forest-gameplay.png

[24902-forest-gameplay+(1).png|24902]

You see the width is the same for both resolutions and only the screen height varies.

Any idea of how I can do this?

Thanks in advance!

EDIT:

Found this: Controlling Aspect Ratio in Unity

Is there a way to edit it to scale height instead of adding black frames? (keeping the width)

Up!

You need to change your camera orotographics size following the next formula:

ortographicSize = constantWidth / aspectratio * 2f;

try this:

    var verticalFOV : float =60;
    var forcedAspectRatio: float = 0.75;
    var manualNearClipPlane : float = 0.01;
    var manualFarClipPlane : float = 1000;
     
    function Update(){
        camera.projectionMatrix = Matrix4x4.Perspective(verticalFOV, forcedAspectRatio, manualNearClipPlane, manualFarClipPlane);
    }