I would like to create a game like a minesweeper. And I ran into a problem while creating the game. How to count nearby bombs? I can create 8 child objects with a collider on an empty slot and place them in all directions to count the bombs, but I think this is a bad solution.btw i am bad at coding.Thank you in advance!
You can simply make a 2d grid and work without colliders. Then for a given cell you can simply count nearby bombs by looping through 8 nearby cells.
If you insist on using gridless approach, then call Physics2D.OverlapCircle or Physics2D.OverlapBox Unity - Scripting API: Physics2D.OverlapCircle eight times at position of nearby cells, and check if it hits anything, and whether that “anything” is a bomb.
2 Likes
