Match Game Mechanics

This example shows how to implement basic matching mechanics.

It has two scripts; one for a custom cell, and a grid behaviour for the main logic. The cell has some maintenance fields, but is otherwise quite dumb. Keeping cells dumb is good practice. It helps centralize logic, and make cells more re-usable.

The grid behaviour is simple. It initializes cells to random values. When a cell is clicked, it tries to find a match. If the match is big enough (3 cells or more), the match cells are destroyed. New cells are created as necessary, and cells fall into the empty spaces. This last bit is the trickiest. For cells already in the grid, we count the number of empty spaces below each cell. We then lerp the cell from its current position to the correct position downwards (based on the number of empty cells below). We also count the number of empty cells in each column, and generate as many new cells. These cells are position above the grid, and made to fall down similar to the other cells.

To run the example:

  1. Import it into a new project.
  2. Import Grids 1.8.
  3. Open the scene MatchGame in the MatchGame folder.
  4. Run it.

Download

MatchGame.unitypackage

6 thoughts on “Match Game Mechanics”

  1. Hi yes there is a namespace error on 1.14

    So to fix it add this line at the top of the offending file 🙂

    using Gamelogic.Grids.Examples;

  2. Pingback: Creating match 3 games in Unity

  3. Pingback: Creating Match 3 Games in Unity – by Pietro Polsinelligamedev.fm | gamedev.fm

Comments are closed.

Scroll to Top