Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

Having trouble preparing my game for different resolutions and aspect ratios

Discussion in '2D' started by Tigro, Jul 25, 2020.

  1. Tigro

    Tigro

    Joined:
    Apr 25, 2014
    Posts:
    58
    I'm finishing up a mobile 2D game of mine and am having quite some troubles figuring out the way to properly scale it for the multitude of resolutions that there is on the market. So right now, I control the camera in such a way that I have a script attach to the camera which establishes the ortographicSize like this:

    Code (CSharp):
    1. public class OrthoSizeSetter : MonoBehaviour {
    2.  
    3.     public Main mainScriptHolder;
    4.  
    5.     [Range(0, 2)]
    6.     public float zoomBias = 1.0f;
    7.  
    8.     // Use this for initialization
    9.     void Start()
    10.     {
    11.         Camera.main.orthographicSize = (mainScriptHolder.mapWidth * Screen.height / Screen.width * 0.5f) * zoomBias;
    12.     }
    13. }
    and another one which controls the projectionMatrix:

    Code (CSharp):
    1. public class CameraAspectController : MonoBehaviour {
    2.  
    3.     public float orthographicSize = 100;
    4.     public float aspect = 0.625f;
    5.     void Update()
    6.     {
    7.         Camera.main.projectionMatrix = Matrix4x4.Ortho(
    8.                 -orthographicSize * aspect, orthographicSize * aspect,
    9.                 -orthographicSize, orthographicSize,
    10.                 Camera.main.nearClipPlane, Camera.main.farClipPlane);
    11.     }
    12. }
    Now, this works pretty well for some devices - for example when running the game in the Mate 20 Pro or the Samsung S10+, I get exactly what I want:


    However, running it on devices that aren't as tall makes it basically unplayable, like an iPhone 8 or the Google Pixel XL:




    Why is that so? How can I counter it to have it scale as easily to such devices as it does to the ones in the first group?
     
  2. Tigro

    Tigro

    Joined:
    Apr 25, 2014
    Posts:
    58
    No ideas? :(