I need to find the position of the closest point from the bounds of multiple colliders. Right now I'm using
This works great for one collider, but as when I add a new collider, it doesn't update.
I've drawn a quick picture to illustrate what I'm trying to say. The black box is the area I want to check in, the red boxes are the colliders with numbers representing the order they entered the black box. The green star is what the code currently says the closest point is, and the blue star is the expected result. The purple star is the position I'm checking for, the blue star should be the closest point to the purple star.
I found this answer to a similar question on answers.unity3d.com. However, I feel like that could be very inefficient because there will be many, probably up to 50 of these box checking scripts running at the same time.
I've also tried using
Physics.BoxCast but that gave very wild results. The area it was checking was very different to what I wanted, and also what I was visualizing with gizmos. Also, the whole idea of boxcasts are very very confusing so I would rather something else.
What is the best way to find the closest point on the bounds of multiple colliders within a certain area?