public void CheckForDeletion() { List <TileBase> tilesToRemove = new List <TileBase>(); List <TileBase> removeList = new List <TileBase>(); for (int x = 0; x < _gridSize.x; x++) { TileType typeBuffer = null; int matchBuffer = 0; for (int y = 0; y < _gridSize.y; y++) { if (typeBuffer != _grid[x, y].tileType) { typeBuffer = _grid[x, y].tileType; matchBuffer = 1; } else { matchBuffer++; if (matchBuffer == 3) { if (!removeList.Contains(_grid[x, y])) { removeList.Add(_grid[x, y]); } if (!removeList.Contains(_grid[x, y - 1])) { removeList.Add(_grid[x, y - 1]); } if (!removeList.Contains(_grid[x, y - 2])) { removeList.Add(_grid[x, y - 2]); } } if (matchBuffer > 3) { if (!removeList.Contains(_grid[x, y])) { removeList.Add(_grid[x, y]); } } } } } for (int y = 0; y < _gridSize.y; y++) { TileType typeBuffer = null; int matchBuffer = 0; for (int x = 0; x < _gridSize.x; x++) { if (typeBuffer != _grid[x, y].tileType) { typeBuffer = _grid[x, y].tileType; matchBuffer = 1; } else { matchBuffer++; if (matchBuffer == 3) { if (!removeList.Contains(_grid[x, y])) { removeList.Add(_grid[x, y]); } if (!removeList.Contains(_grid[x - 1, y])) { removeList.Add(_grid[x - 1, y]); } if (!removeList.Contains(_grid[x - 2, y])) { removeList.Add(_grid[x - 2, y]); } } if (matchBuffer > 3) { if (!removeList.Contains(_grid[x, y])) { removeList.Add(_grid[x, y]); } } } } } for (int i = 0; i < removeList.Count; i++) { Core.Ammo[removeList[i].tileType].AddValue(1); removeList[i].Destroy(); } instance.DropDownTiles(); }