# How does Aspect Ratio and Resolution work in Unity?

I am trying to make progress in Unity on understanding how aspect ratios and resolution work. I can't quite wrap my head around the topic. For example, I am trying to make a simple breakout style game, but in order to do that, I need to consider the world units and how each brick would fit into the scene. From what I have read, world units are dependent on screen resolution and aspect ratio. How would I be able to make something like this if mobile games are played on different devices (and ones with notches nonetheless). Also I'd like to know how to achieve this without using the tacky black bars that some games use.

Any information regarding this would be extremely appreciated.

If your project is designed correctly, you should never need to adjust world units or positions of most objects for different screen resolutions/aspect ratios. You would instead adjust the camera.

To accommodate different aspect ratios, you would write a script that adjusts the camera zoom or position based on the screen aspect ratio. For example,

//This is a very simple example. You will need to adjust the numbers for
//your specific game and may need to add more if-else conditions or make
[RequireComponent(typeof(Camera))]
public class CameraAspectRatioAdjuster : MonoBehaviour {
void Start() {
Camera camera = GetComponent<Camera>();
float aspectRatio = Screen.width / Screen.height;
//you will need to change these numbers
if (aspectRatio > (16 / 9f) {
camera.fieldOfView = 60;
} else if (aspectRatio > 4 / 3f) {
camera.fieldOfView = 55;
} else {
camera.fieldOfView = 50;
}
//alternatively, you could try a one-size-fits-all-formula
//camera.fieldOfView = aspectRatio * 60;
}
}


There is no need for this script to account for resolution.

As for the user interface / HUD, that should be built in a Canvas using a canvas scaler. A properly built canvas with canvas scaler will generally look good on different screen resolutions/aspect ratios without needing to make any layout adjustments from code.