Search Unity

Question Camera to cover entire screen?

Discussion in '2D' started by scryedzxp, May 1, 2023.

  1. scryedzxp

    scryedzxp

    Joined:
    May 14, 2013
    Posts:
    47
    I created a new Android 2D mobile project set to the following resolution:

    upload_2023-5-1_11-28-0.png

    But I noticed the camera doesn't cover the entire screen.

    upload_2023-5-1_11-36-45.png

    I know I can manually adjust the Position and Size fields of the camera so it covers the entire screen (Transform.Scale doesn't seem to do anything):

    upload_2023-5-1_11-43-36.png

    but how can I do this through a script so that it accounts for all resolutions/aspect ratios?

    I tried using the following solution (2d - Scale camera to fit screen size unity - Game Development Stack Exchange) but that didn't work for me.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,742
  3. scryedzxp

    scryedzxp

    Joined:
    May 14, 2013
    Posts:
    47
    Sorry if I wasn't clear. In this scenario, I'm just using the canvas to illustrate the screen resolution.

    In my previous picture, you can see the sprite is outside of the camera and as a result it's not being rendered. I would like to "scale" the camera to fit that screen resolution so it can render all of the 2D sprites:



    To elaborate further, the following is the same setup as above but I added 2 more sprites (near what should be the corners of a phone screen). I would like the camera to fit the screen so all 3 sprites are rendered regardless of whatever resolution I set it to:

    upload_2023-5-1_12-53-59.png
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,742
    Camera stuff is pretty tricky... you may wish to consider using Cinemachine from the Unity Package Manager.

    There's even a dedicated forum: https://forum.unity.com/forums/cinemachine.136/

    Cinemachine has 'keep all these things in sight' kinds of methods for stuff like this.