I cannot detect the positions of objects

Hello friends, I am making a game whose logic is similar to the candy crush game. But I couldn’t understand how to detect two identical objects coming side by side or diagonally. The sample part of the game is below.

Image:

This stuff is generally better handled by an underlying data layer, rather than the position of game objects in your scene.

If you maintain a 2D array of tile slots that actual gameplay tiles can assign themselves into, then it becomes trivial to work out what is next to or nearby any given slot.

Then I’ll add a controller to the ground and fix it

Here’s a fully-operational Match3 game engine, including source code (see comments):

Tile-based / grid-based 2D games: match3, tetris, chips challenge, rogue, etc:

For any tile-based game such as Match3 or Tetris or a grid-based Roguelike, do all the logical comparisons in your own data storage mechanism for the tiles, such as a 2D array of tiles.

Otherwise you needlessly bind your game logic into Unity objects and the Unity API, making it about 10x more complicated than it needs to be.

If you have no idea how to work with 2D arrays, hurry to some basic C# tutorials for the language portions of it, then look at any good tutorial that uses a 2D array

Here is my Match3 demo using this technique of storing data in a grid. Full source linked in game comments.

It stores all of its data in a 2D array:

PieceController[,] Board;

This allows for easy simple checking in code, not relying on anything like physics.

You should strive to use that pattern for all logic, then only present what is happening in scene.