# Rule to change orthographic size to fit object inside camera rect

I'm working on a 2D zoom effect using an orthographic camera. So far I have a zoom value that I'm using but I would like to know if there's a rule or formula to obtain the exact size for my orthographic camera in order to fit the object (target) exactly inside the camera rect.

Here's a sample of my code

var v = new Vector3(target.position.x, transform.position.y, target.position.z);
mainCam.transform.position = Vector3.Lerp(mainCam.transform.position, v , smooth * Time.deltaTime);
mainCam.orthographicSize = Mathf.Lerp(mainCam.orthographicSize, zoom ,smooth*Time.deltaTime);


I would like to know how to calculate the zoom variable instead of using a constant one.

I tried to upload the images directly but it failed so i'm providing a link, first image contains the object properties, second is a view of the object using a perspective camera (3d mode)and the third is what my camera sees when it's zoomed (the default orthographic size is 0.5 and the zoom size is equal to 0.1).