//if tile is swiped over public int Swiped(out BasePlant plant) { int tempScore = 0; plant = basePlant; //if the plant is already active if (basePlant.GetActive()) { //get the score from the plant tempScore = basePlant.GetScore(); Debug.Log(basePlant.GetScore()); //if the plant is type of double plant if (basePlant is DoubleScorePlant) { //white text FloatingTextManager.CreateFloatingText("+" + basePlant.GetScore().ToString(), basePlant.transform, Color.white); } else if (basePlant is NormalPlant) { //yellow text FloatingTextManager.CreateFloatingText("+" + basePlant.GetScore().ToString(), basePlant.transform); } else if (basePlant is DebuffPlant) { FloatingTextManager.CreateFloatingText("+" + basePlant.GetScore().ToString(), basePlant.transform, Color.blue); DebuffPlant debuff = basePlant as DebuffPlant; Destroy(lightning); } //activate the dead plant animation m_animator.SetTrigger("DeadPlant"); //Set the plant state to be inactive basePlant.SetActive(false); for (int i = 0; i < emmiters.Count; i++) { emmiters [i].Play(); } } return(tempScore); }
//add randomised plant component public void AddNewPlantComponent() { //Set up a random percentage chance int chance = Random.Range(0, 100); //if the chance is greater than 90 (10% chance) if (chance >= 75) { //spawn debuff plant (lightning plant) plantComponentType = PlantComponentType.DEBUFFPLANT; } //if the chance is greater than 70 but less than 90 (20% chance) else if (chance > 55 && chance < 75) { //Spawn double score plant plantComponentType = PlantComponentType.DOUBLESCOREPLANT; } //otherwise just spawn a generic 1 point plant (70%) else { //Spawn Normal Plant plantComponentType = PlantComponentType.NORMALPLANT; } m_animator.SetTrigger("Spawn"); switch (plantComponentType) { case PlantComponentType.NORMALPLANT: m_animator.enabled = false; basePlant = gameObject.AddComponent <NormalPlant> (); basePlant.SetSprite(sprites [0]); sr.sprite = sprites [0]; m_animator.enabled = true; m_animator.SetTrigger("BulbPlant"); break; case PlantComponentType.DOUBLESCOREPLANT: m_animator.enabled = false; basePlant = gameObject.AddComponent <DoubleScorePlant> (); basePlant.SetSprite(sprites [1]); sr.sprite = sprites [1]; m_animator.enabled = true; m_animator.SetTrigger("VenusPlant"); break; case PlantComponentType.DEBUFFPLANT: m_animator.enabled = false; basePlant = gameObject.AddComponent <DebuffPlant> (); basePlant.SetSprite(sprites [2]); sr.sprite = sprites [2]; m_animator.enabled = true; m_animator.SetTrigger("YellowPlant"); break; case PlantComponentType.ELECTRICPLANT: basePlant = gameObject.AddComponent <ElectricPlant> (); basePlant.SetSprite(sprites [3]); sr.sprite = sprites [3]; break; } basePlant.SetActive(true); FirstTimeSpawn = false; }