How to make the camera not go too far?

I’m making a 2D game where the camera is supposed to be static and have a problem with the “resolution” of the camera. Whenever I stretch the Game window the area you see expands with it so I tried to solve it with this:

    void CamSize()
    {
        float A=1280/cam.pixelWidth;
        Debug.Log(cam.pixelWidth);
        cam.orthographicSize=5*A;
    }

which runs in FixedUpdate()

I get this error:
Screen position out of view frustum (screen pos 14.000000, 4.000000) (Camera rect 0 0 1337 674)
UnityEngine.SendMouseEvents:smile:oSendMouseEvents(Int32)

I really don’t know what else to try as I googled this and it went to changing the sprite’s pixel per unit and changing the camera’s size to half the resolution’s height which would effectively break the game totally.
Do I just give up with this and let the view stretch how much it wants or is this possible to fix as the

cam.orthographicSize=5*A;

doesn’t constantly change it. It just goes between 0 to 10 pretty much snapping 0,5 and 10.

If you set your game up for normal standard def TV (4:3 aspect ratio) and play it on widescreen (16:9), you need to decide what you want to show on the edges.

By default Unity’s cameras will show “what is there.” They are just mathematical constructs that project the world for reendering.

If you want blackness there, one way is to letterbox it on the sides. You can put varying-sized black UI panels in if you like, or else use a separate camera that looks at a pair of black boxes and layer it in front of your camera, sort of like “curtains” on a stage.e