Okay, so there are a number of ways to find nearest object to any given object within a set range.
but which one is the least intensive?
Off my head here are some methods;
The Choice of Foreach, For loops and Ienumerator
Iterating through lists and arrays containing all game objects and checking the vector2 or 3 distance between them.
Create a collider, and check collisions, or bounds.contains(transform position) of the object.
Lets say i have a large hex grid, and i do not want to check all hexes to get an objects neighbours. Perhaps teleporting a collider with a set range and then checking its bounds would be the most efficient method?
I suggest you make a method to retrive the hexagon at a certain hex-coordinate. Then it’s just that you get the 6 neighbours in each direction from the hex-coordinate of your hexagon in question. You should have some mapping from a certain hex-coordinate to the instance of the hexagon. A dictionary should be fine.
But Kurt’s advise still applies. If you have no performance issue make optimizations when it’s necessary. When you need neighbourship for example for pathfinding you should create the list of neighbours only once and store the references or indices in the hexes themselfes.