public PlantComponent(PlantComponentType compType, string c)
 {
     componentType = compType;
     CreateID();
     color  = c;
     locked = false;
 }
Example #2
0
    //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;
    }