- Home /
How do you find adjacent tiles of the same type in grid array [x,y].type == [x+1,y].type
Does anyone know what I'm doing wrong?
I want to detect when four or more of the same colours are connected using an array? like the black in this picture
Heres what I have atm..
public class Tile { public GameObject tileObj; public string type; public Tile(GameObject obj, string t) { tileObj = obj; type = t; }
}
public class colourMatch : MonoBehaviour {
 public static int gridHeight = 270; 
 public static int gridWidth = 150; 
 public Tile[,] tiles = new Tile[gridWidth, gridHeight];
 public GameObject[] tile;
 public static int counter = 1;
 // Use this for initialization
 void Start () {
     
 }
 public void UpdateGridColour (MoveInGridClockwise Blob) 
 {
     counter = 1; 
     for (int y = 0; y < gridHeight; ++y) 
     {
         for (int x = 1; x < gridWidth; ++x) 
         {
             if (tiles[x, y] != null) 
             {
                 if (tiles [x, y].type == tiles [x + 1, y].type) {
                     counter++; 
                     print (counter); 
                 } else {
                     counter = 1; 
                     print (counter); 
                 }
             }
         }
     }
 }

How does your code do what you want to do? I don't see the connection there.
So you want to detect adjacent black tiles when you click on one of them or you want to get all groups of 4 or more adjacent same colour tiles in the grid?
All groups of 4 or more once the 2 colours at the top of the screen (black purple in this pic) have landed at the bottom of the grid.. When the black and blue landed I want it to detect that 4 black (or any same colours) are now connected..
Your answer
 
 
             Follow this Question
Related Questions
How to create a rotating tiles with walls on edges of tiles? 0 Answers
2D Tile Map Question 0 Answers
Grid and or Tile System 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                