help with making resolution independent app

Ok i truly can’t find any concrete answers regarding this issue with making apps. Smartphones come with many screen sizes so there’s gotta some way to code it so that it deals with them all.

In my particular 2D app, distance from the center to the edge of the screen matters, so I want to be able to have the game SCALE everything smaller or larger based on the current resolution, so that if in some DEFAULT(right?) set resolution its 5 meters from the center to the edge of the screen, the game will scale or shrink to maintain 5 METERS from the center to the edge of the screen.

I found code that can make the background sprite always scale to fit the screen width and screen height:

    function ResizeSpriteToScreen() {
    var sr = GetComponent(SpriteRenderer);
    if (sr == null) return;
    transform.localScale = Vector3(1,1,1);
    var width = sr.sprite.bounds.size.x;
    var height = sr.sprite.bounds.size.y;
    var worldScreenHeight = Camera.main.orthographicSize * 2.0;
    var worldScreenWidth = worldScreenHeight / Screen.height * Screen.width;
    transform.localScale.x = worldScreenWidth / width;
    transform.localScale.y = worldScreenHeight / height;

Maybe I can adjust all the other sprite scales based on the background sprite scale set in that script? Like some kind of ratio?
I’m really not sure how to best approach this. This is my first smartphone app.
I hate coding this kind of utility stuff instead of focusing on making the game.
Any help is really appreciated, thanks :slight_smile:

I have made similar question: Click here

The Idea is to multiplicate your camera to Matrix4x4