//Method that sends new diamonds private void SendNewDiamonds() { for (int column = 0; column < columns; column++) { //Calculates position for new diamond float positionX = column * 1.5f; float positionY = 0f; if (column % 2 != 0) { positionY = -1f; } //If no diamond exist on the location creates new diamond if (GameObject.Find(positionX + "," + positionY) == null) { //If score counter for the bomb is more than the score that bomb needs to be sent //Sends bomb diamond if (bombScoreCounter >= sendBombScore) { BombDiamond newDiamond = Instantiate(bombTile, transform); newDiamond.GetComponent <SpriteRenderer>().color = ColorChooser(); //Picks a random color newDiamond.transform.position = new Vector2(positionX, positionY); //Sets the position bombScoreCounter = 0; //Resets the counter } //Sends regular diamond else { Diamond newDiamond = Instantiate(tile, transform); newDiamond.GetComponent <SpriteRenderer>().color = ColorChooser(); //Picks a rabdom color newDiamond.transform.position = new Vector2(positionX, positionY); //Sets the position } } } }
public void InstantiateDiamond() { var diamondColor = diamond.GetComponent <SpriteRenderer>(); switch (Random.Range(0, 5)) { case 0: diamondColor.color = Color.red; break; case 1: diamondColor.color = Color.blue; break; case 2: diamondColor.color = Color.white; break; case 3: diamondColor.color = Color.green; break; default: diamondColor.color = Color.yellow; break; } Instantiate(diamond, new Vector2(Random.Range(-2.5f, 2.5f), 6), Quaternion.identity); }
// Method that creates diamonds private void CreateTiles() { Color previousColor = Color.black; //Temporary color //Loops for rows and columns for (int row = 0; row < rows; row++) { for (int column = 0; column < columns; column++) { Diamond diamond = Instantiate(tile, transform); Color newColor = ColorChooser(); //If the color of diamond is same as previous one picks a new color while (newColor == previousColor) { newColor = ColorChooser(); } previousColor = newColor; // Sets new color as previous color diamond.GetComponent <SpriteRenderer>().color = newColor; //X and Y positions float posX = column * 1.5f; float posY = 0f; //Calculates position of hexagon correctly if (column % 2 != 0) { posY = row * -2f - 1f; } else { posY = row * -2f; } //Sets the position of diamond diamond.transform.position = new Vector2(posX, posY); } } }