By means of a GetComponent we store the reference in the variable declared in the previous point.We will need it to change the color of the cell. Declare a variable to store the TileRenderer of this cell.A static variable means that it is shared among all instances of a class, so for each tile, that variable will always have the same value. Declare a static variable to store the currently selected tile.
The lines we added deal with the selection, as we said a little while ago. Let’s create a script, call it Tile and write the following: private static Tile selected // 1 We must provide feedback to the user to show if a cell is checked or not, to make it change the color of the selected cell. If you click on a non-adjacent cell, the currently selected one will be deselected, the new one selected without any swap. We created our grid, now we have to make it interactive! What we are going to do now is to give the possibility to select the cells with a click, and swap them with a neighboring cell by clicking on it. This is part 2 of the tutorial on How to Create a match 3 game in Unity, here you can find the links to other parts: Hey, welcome to the second part of the this amazing tutorial, I hope you enjoyed the first part but now it’s time to move forward and develop all the logic to move the cells inside our beautiful grid.