I need to select the objects that I circled, for this I made a script that calculates 4 rays from the camera to the frame (scriptshot). so i have 4 start points and 4 end points, how to form a cube from this to check,OverlapBox?
i have variable
Vector3[] RayOrig // 4 point sources from the camera
Vector3[] RayDir // 4 direction points from the camera
Vector3[] RayHit // 4 camera hit points
Given the 4 ray hit positions, you have a square in the XZ plane (the floor). Assuming that choosing the height of the cube yourself is ok for your purpose, you can calculate the center and half extents that Physics.OverlapBox needs like this:
A) calculate the maximum of all 4 points using Vector3.Max
B) calculate the minimum of all 4 points using Vector3.Min
C) your center is (max + min) / 2 and your half extents (max - min)/2. That is, the center is the average of the two corners that are further apart from each other, and the half extents half the width/height of the rectangle.