public Line2D GetNearestEdge(Vector2 point, out Vector2 intersection) { Line2D output = new Line2D(); intersection = Vector3.zero; float dist = Mathf.Infinity; for (int i = 0; i < verts.Length; i++) { Line2D line = new Line2D( verts[i], (i == verts.Length - 1) ? verts[0] : verts[i + 1]); Vector2 newIntersection = line.GetClosestPointSegment(point); float newDist = Vector2.Distance(point, newIntersection); if (newDist < dist) { dist = newDist; output = line; intersection = newIntersection; } } return(output); }