Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Canvas ratio fixed to landscape?

Discussion in 'WebGL' started by karmatha, Jul 17, 2020.

  1. karmatha


    Aug 25, 2012
    Hi my goal is to make my webgl build responsive, in the sense that it will always try to fill out as much of the screen as possible, while keeping aspect ratio. So letterbox/pillarbox when needed.

    To achieve this I removed the fixed width and height from

    <div id="unityContainer" style="width: %UNITY_WIDTH%px; height: %UNITY_HEIGHT%px; margin: auto"></div>

    Then I noticed the canvas element within that div would take up 100% width and adjust the height to keep aspect ratio. I noticed the width and height were being set by Unity. This works well when the game is meant to be in 'landscape' mode but now I have the situation where I'd like to height to be leading and the width to follow.

    I am using a canvas scaler on my main canvas like this

    and it seems to have the desired effect in the unity player but in webgl the canvas still gets 100% width instead of 100% height.

    It's almost as if the canvas is adhering to some secret aspect ratio that I'm not able to set. Or did I miss something?