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:
- Import it into a new project.
- Import Grids 1.8.
- Open the scene MatchGame in the MatchGame folder.
- Run it.
The game dont work on the Current version (1.13)
same here
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;
Thanks @nalinsharma:disqus it works!
Pingback: Creating match 3 games in Unity
Pingback: Creating Match 3 Games in Unity – by Pietro Polsinelligamedev.fm | gamedev.fm