Stuck at how to code something


I have a bunch of sphere colliders spead out on the xz plane.
from the top i fire a ray at the position of the mouse to intersect hit any of the colliders. This works but there is a massive performance drop with only about 30 colliders in the scene. So

Coroutines, i looked at but dont return a type that is useful to me, i want the gameobject back

Threads also are not useful because they dont allow you to use the unity api, ie. the raycast

so i dont know how to go forward from here.

Im looking for a way of getting the gameobject back without the performance hit
Any help would be greatly appreciated.


Sphere collision is one of the cheapest collisions possible, the performance drop is probably related to your implementation at the moment.

Do you have the raycast code built into every cell? That would mean if you have 30 cells, 30 raycasts are being created. You should only have one raycast check per mouse click. Just create a single gameobject with a new class that handles the `getHitCell(); function.