Finding the "center" of 4 objects

Hi. I’m trying to use a script to find the “center point” (not sure of a better name to call it) between 4 objects on a 2D plane. For example, if the objects were located at the four corners of a square field 10 feet on each side, the “center” would be the origin of the field (0,0). But I’m not sure how to find these coordinates. The purpose is to have a camera follow a game object that is always located at this center so that I can keep 4 players in view at one time. Of course I will still need to work on zoom afterwards but I want to get moving the camera around ready first. Does anyone have any advice?

Assuming the center point of each object is the pivot, you should be able to just add up the four transform.positions of the four objects and divide the resulting vector by 4.

Addition: If the pivot point is not at the center, pick one of the bounds of one of the objects. Then use Bounds.Encapsulate() on the corner points of the bounds for the other objects. Given 2D with no rotation, you can do it with four points per other object. The Bounds.center will be the center point, and the resulting bounds also gives you the extent of the camera view that you need to see all four objects in their entirety.

Addition2: Or you can just find the min and max x and y for all the bounds for all the objects. Half way between the two will be the center, and the min and max gives you the range the camera can see.