Camera and UI settings for aspect ratio independent 2D game
Dear Community,
I recently started getting familiar with Unity and I am trying to port my half-finished 2D game from Monogame to Unity. I got a bit stuck at the proper camera and Image set up.
What I would like to achieve is a resolution and aspect ratio independent game. The virtual resolution I am using is 1920x1200. At the moment everything looks fine at this 16:10 aspect ratio. I downloaded a script that I added to my camera: http://gamedesigntheory.blogspot.co.uk/2010/09/controlling-aspect-ratio-in-unity.html I changed the hard-coded values to public variables, so I can use them in the editor.
My camera is set to be ortographic, the canvas of the UI Image is set to use my above mentioned virtual resolution, but something is still wrong, because when I run the game I can still see the black widescreen areas above and below, or on both sides of the screen (depending on which resolution I chose from the popup settings).
My question is rather general and not related to my current problems: How do I need to set up a UI elements-only game's :
camera (ortographic, persepctive? fov? etc...)?
UI elements and their canvas (I'd rather not use the anchors because the positions and sizes should be scaled down or up depending on the actual resolution - virtual resolution difference)?
( 3. extra: As I am creating prefabs from buttons and text inputs because I have custom images appearing on them (disabled image, mouseover image, pressed image, ...), can I use one canvas for all of my controls, or do I need to create a canvas for each control? Any performance problems when using multiple canvases? Will the canvas size affect my controls in any ways?)
Thank you in advance and my apology for these beginner questions! Tried as I might have, I could not find answers though I spent my last 3 days on searching for then. :)
Answer by Metalmolekula · Nov 14, 2016 at 10:38 PM
Ok, basically this video tells you how to change the anchors, pivot and basically everything to be able to give your UI elements an aspect ratio and resolution-free look:
https://www.youtube.com/watch?v=svyDgYz5idg
It's not easy, and at the moment I am not sure how to properly do this when I create the prefabs for controls appearing multiple times at different positions on the screen, but hopefully it will not be a big problem.
Your answer
Follow this Question
Related Questions
Pixel jitter/flicker while camera movement (2D) 2 Answers
Camera Bounds in Complex Shape 1 Answer
Jittery movement of the camera when rotating AND moving - 2D top down 3 Answers
After getting center of screen, my onClick commands stop working 0 Answers
Camera is making trail in moving objects 0 Answers