OK I don’t know if this is possible, but I’m hoping someone has a good solution other than a bunch of raycasts. I have a crosshair texture on screen and I’d like to get an array of all objects that are behind/underneath it because at the distances I’m working with a raycast is too precise and often misses the object I want to select. Any ideas? I thought of using the screen rectangle of the texture but I didn’t see a way to get a list of objects within that rectangle. My other solution is to raycast from various points in the texture and then build the list myself.
Take a look at this:
Pretty tough to suggest something without knowing more about how the objects you want to select might be placed in the scene.
Regardless, I think you’ll have to come up with a suiting algorithm to check which objects that should be selected. Limiting the search space with buckets or something might speed things up if you have a large scene and a multitude of objects.
If you do want to use raycasts, you could always use 3-4 casts from the camera (to set the “search space”) and then link larger colliders to your small objects to give them a “radius”.
Just some ideas.
If the objects you want to test have rigidbodies, then you could have a long pyramid-shaped trigger that moves with and extends outward from the crosshair texture (set the rotation using camera.ScreenPointToRay and Quaternion.LookRotation), and anything entering the trigger would therefore be “underneath” the crosshair.
–Eric