//update void Update() { //keep refreshing the state information on the animator m_stateInfo = m_animator.GetCurrentAnimatorStateInfo(0); //if the base plant isn't active if (!basePlant.GetActive()) { //Start respawning a plant basePlant.SetSprite(sprites[4]); StartTimer(); } //if the baseplant is a debuff plant if (basePlant is DebuffPlant) { //start swapping the lightning buff on the plant SwapLightningDebuff(); } }
//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; }