Scaling game to fit screen size

I’m having problems with scaling my game to fit all mobile screens.
So this is my Canvas Scaler:
alt text

I didn’t really understand the Reference Resolution thing so, for now, it’s set to my screen size.
I also messed with anchors a bit. When I started I anchored all my UI elements to the sides of the screen I wanted them to stay close to.

Now I have 2 problems:

The first one is that I separated my UI elements into different logical groups, and each group is inside its own empty game object. Thing is, now the anchors are on the sides of this empty game object instead of being on the canvas. What can I do with that?

The second problem is that after I make my UI look good, what about the game itself? The UI might fit into any screen, but for example, on a screen with a smaller width, my player can travel outside the screen. (the player moves right and left). Another example is my background being cut to fit the new screen size. How do I fit the whole game into the new screen size, and not only the UI?


About my second problem, I fixed it with adding black bars for different aspect ratios as this wonderful video explains: Handling different aspect ratios in your Unity 2D games [RNDBITS-030] - YouTube

Still got the first problem with my UI. can’t anchor like I used to because my images, texts and buttons are inside an empty game object and not directly beneath the canvas.


I found the full tutorial that solve this issue.
Tested and it worked for me.

Link: [SOLVED] Full tutorial: Build 2D game fit to any device screen size, resolution in Unity 2018 - YouTube