I created a new Android 2D mobile project set to the following resolution:
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:
It can be very fiddly but it is super-powerful once you reach comfort with the UI.
Building upon Praetor’s great post above, let me suggest this approach:
make a quick first draft of your UI.
in the Unity game window change the shape / dimensions of your Game window (you can even make your own resolutions)
see what happens to your UI in this new shape window
iterate and fix your anchors and scalings and whatnot
Make sure you do not overlook the Canvas Scaler settings. Personally I (almost) …
That seems excessive… What is the text of the actual complaint from them?
Make something like this with a fixed aspect ratio (in this case 2:1, maybe you need 3:1 or whatever suits your buttons), and ALL your buttons anchored inside it to never move within that box:
[7337383--891847--fixed_aspect_ratio_box.png]
then anchor that fixed against the bottom center (red dot below).
On the ipad it looks like:
[7337383--891850--ipad.png]
on the iPhone it looks like:
[7337383--891853--iphonex.pn…
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:
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.