private Tile GenerateNewTile(Vector2Int adress) { Tile tile; tile = TilesStash.GetTile(); //Try apply tile from stash if (tile == null) //Check for existing tile { tile = Instantiate(prefabTile, transform); //Instantiate new tile } TileColor tileColor; do { tileColor = (TileColor)Random.Range(0, System.Enum.GetValues(typeof(TileColor)).Length); } while ( //Generate new color while there is a ready match. - Protect from pregenerated matches (adress.x > 1 && tileColor == tilesOnField[adress.x - 1][adress.y].tileColor && tileColor == tilesOnField[adress.x - 2][adress.y].tileColor) || //Check for ready match by x (adress.y > 1 && tileColor == tilesOnField[adress.x][adress.y - 1].tileColor && tileColor == tilesOnField[adress.x][adress.y - 2].tileColor) //Check for ready match by y ); tile.ResetColor(tileColor); tile.transform.localPosition = new Vector3(adress.x, tilesOnField[0].Length - 1); //Move tile on top of column tile.ResetAdress(new Vector2Int(adress.x, adress.y)); return(tile); }
public void Burst() { TilesStash.AddTile(this); }