- Home /
Need help with "Tetris" or "Match 3" puzzle logic
So I'm stuck trying to figure out how to get Unity to tell when the right blocks are matching
Example:
I get 3 identical blocks in a row (one next to the other), how do I get Unity recognize that these blocks are aligned and it's ok to destroy them (like Tetris or Match 3)
Collision, Tags, maybe?
The particulars of this answer highly depend on your implementation and goals...how you are moving your blocks, how you are marking your blocks, and what counts as rows. Something along the lines of @Jinxology's answer is how I would approach the problem. When similar questions to this one have been asked in the past, the alternate solution of Raycasting() has been suggested. When each block is not moving, the block uses raycasts left and right to get properties of the neighbors. If they are also not moving and of the same type, then they can be scheduled to be destroyed.
Answer by Jinxology · Jan 20, 2014 at 10:30 PM
I would setup a data layer (essentially a 2D array) and store the current "color" at each point (initially -1 for all locations). When a block/node snaps into a place, you can calculate a nodes position in the area by it's physical location, then set that data layer's grid accordingly.
For example, if my scene is 100x100 units, and my blocks are 10x10 squares, when a block is at 90,90 then that maps to dataGrid[9][9].
Each time a you record new data, you need to scan your data for a match 3 (guessing a recursive function that walks the data 1 node at time), or a full line of the same color for Tetris (probably a lot quicker/easier).
Your answer

Follow this Question
Related Questions
How to make coloured tetris-like blocks during runtime 0 Answers
Puzzle open door ? 1 Answer
OnMouseUp is nulling inputs 0 Answers