raycasting to a scripted object

I have a hexagon prefab, from this prefab my script creates a hexagonal tiled grid map. I am attempting to raycast in a mini map that i have created, and use that to move the main camera. That is all working fine except for one main point. The hexagonal grid does not have a collider, so the camera jumps around fine if you click over other objects, but not the map itself.

I thought the easiest way to do this would be to give the hexagon prefab a mesh collider. That would straight off the bat solve the problem as the raycast would then find each section of the map. However, when the maps can go up to 22,500 hexagons (possibly higher) i’m concerned that performance is going to be an issue having that many mesh colliders, when all they are going to be used for is this raycasting.

My idea to fix this was to create a mesh collider for the hexagonal grid as a whole once it has been created. However it looks like it will be alot more complicated than i originally thought as i’d have to add all the colliders of the hexagons together, before destroying the hexagon’s mesh colliders.

I’m pretty new to raycasting in unity, and indeed unity itself, I was desperately hoping that there might be a simpler way within unity to allow my ray to detect the Hexagon grid.

Is there hope? Or do i need to create mesh colliders on the hexagon, combine all of the colliders into a grid collider and then delete the hexagon colliders?

Thanks in advance guys.

  • Edit, not sure why this didn’t occur to me before but have decided to try create a plane behind the grid instead, my question now is, is it possible to match the dimensions of a plane to that of the grid?

Why not just wrap a sphere collider tight around it? Seems a lot of trouble doing it the other way!?

Also best thing to do drop your object into the scene and size it, then drop it in a resources folder (Just create one under Asset’s) then delete from scene / Instantiate it to the required vector3 position:

Use gameobject.find to get find the object then use transform.position.