How to use only the needed result of raycastAll?

Check the distance of the intersection point from the raycast starting point. Keep track of the closest entity hit, apply logic to the closest hit entity