Camera to cover entire screen? (916663)

I created a new Android 2D mobile project set to the following resolution:

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

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

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):

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.

The Camera and Canvas behave like this. They are two completely-different coordinate systems.

As long as the Canvas is set to Screen Space Overlay you’ll be fine.

Here are some notes on UI Anchoring, Scaling, CanvasScaler, etc:

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:

8985178--1236757--upload_2023-5-1_12-53-59.png

Camera stuff is pretty tricky… you may wish to consider using Cinemachine from the Unity Package Manager.

There’s even a dedicated forum: Unity Engine - Unity Discussions

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