public void SpawnItems() { GetComponent <Animator>().SetTrigger("Spawn"); for (int i = 0; i < 3; i++) { #region InstantiateAndSetColor //get the color randomly Color temp = GameManager.ColorManager.TurnRandomColorFromTheme(); GameObject Clone; //instantiate switch (GameManager.StateManager.StateName) { case States.PlayState: Clone = (GameObject)Instantiate(GameManager.GameManagerInstance.ClassicModeItems[Random.Range(0, GameManager.GameManagerInstance.ClassicModeItems.Length)], SpawnSlotList[i].transform); foreach (Image image in Clone.GetComponentsInChildren <Image>().ToList()) { //set the color of children if (image.color.a != 0) //this is for touch area { image.GetComponent <Canvas>().sortingOrder = 5; if (image.gameObject.tag != "Rock") { image.color = temp; } //change sprite theme here switch (theme) { case BlockTheme.Classic: image.sprite = BlockSpriteThemes[0]; break; case BlockTheme.New: image.sprite = BlockSpriteThemes[1]; break; default: break; } } } break; case States.PlayStateRockSolid: int rand = RandomWithProbability.GetRandomValue(new RandomWithProbability.RandomSelection(0, GameManager.GameManagerInstance.ClassicModeItems.Length - 1, 0.9f), new RandomWithProbability.RandomSelection(GameManager.GameManagerInstance.ClassicModeItems.Length, GameManager.GameManagerInstance.RockSolidModeItems.Length - 1, 0.1f)); Clone = (GameObject)Instantiate(GameManager.GameManagerInstance.RockSolidModeItems[rand], SpawnSlotList[i].transform); int rndm = UnityEngine.Random.Range(1, 4); foreach (Image image in Clone.GetComponentsInChildren <Image>().ToList()) { //set the color of children if (image.color.a != 0) { image.GetComponent <Canvas>().sortingOrder = 5; if (image.gameObject.tag != "Rock") { image.color = temp; //change sprite theme here switch (theme) { case BlockTheme.Classic: image.sprite = BlockSpriteThemes[0]; break; case BlockTheme.New: image.sprite = BlockSpriteThemes[1]; break; default: break; } } else if (Clone.CompareTag("Rock")) { GameObject block = image.gameObject; block.GetComponent <Durability>().durability = rndm; //change sprite theme here int drb = block.GetComponent <Durability>().durability; switch (drb) { case 1: image.sprite = RockSprites[0]; break; case 2: image.sprite = RockSprites[1]; break; case 3: image.sprite = RockSprites[2]; break; case 4: image.sprite = RockSprites[3]; break; default: break; } } } } break; case States.PlayStateBomb: Clone = (GameObject)Instantiate(GameManager.GameManagerInstance.ClassicModeItems[Random.Range(0, GameManager.GameManagerInstance.ClassicModeItems.Length)], SpawnSlotList[i].transform); foreach (Image image in Clone.GetComponentsInChildren <Image>().ToList()) { //set the color of children if (image.color.a != 0) { if (image.gameObject.tag != "Rock") { image.color = temp; //change sprite theme here switch (theme) { case BlockTheme.Classic: image.sprite = BlockSpriteThemes[0]; break; case BlockTheme.New: image.sprite = BlockSpriteThemes[1]; break; default: break; } } //change sprite theme here switch (theme) { case BlockTheme.Classic: image.sprite = BlockSpriteThemes[0]; break; case BlockTheme.New: image.sprite = BlockSpriteThemes[1]; break; default: break; } image.GetComponent <Canvas>().sortingOrder = 5; } } break; default: throw new System.Exception("Spawn Error"); } #endregion } }