Resizing orthographic camera to fit 2d sprite on screen

Hello!

I have a game object made up of multiple sprite game objects. Each sprite is a “block” (think terraria / minecraft) and the main gameobject is a collection of these blocks. I need my orthographic camera (it’s a 2d game) to shrink it’s width according to the width of the game object. Basically, I need to do the opposite of what orthographic.size does. The height of the orthographic camera doesn’t matter, but the width does. The main game object that consists of the “ground blocks” must always fill the screen width, the height can then stretch as far as it needs for it to be proportional. I’ve searched for something like “orthographic width”, but found nothing. How would I go about doing this?

Hope my explanation isn’t too muddy.

Also, if you have a suggestion on how to better solve this problem than resizing the width of the camera according to the main game object, please say so.

Thanks!

P.S
Basically, I understand what I probably need to do: calculate the orthographic size depending on the width of the game object that I want to fit on the screen. However, I can’t figure out the maths to do this.

Orthographic size is 1/2 of he vertical size seen by the camera. So try this:

 Camera.main.orthograpthicSize = widthToBeSeen * Screen.height / Screen.width * 0.5;