IEnumerator EvolveTower(TowerEvolutions nextEvolution)
    {
        if (currentEvolution == nextEvolution)
        {
            yield break;
        }

        currentEvolution = nextEvolution;
        currentSettings  = GetTowerSettings(nextEvolution);
        health.RestoreHealth();
        modifier.SetTintColor(new Color(1, 1, 0, 1f), 0.75f);

        yield return(new WaitForSeconds(0.75f));

        switch (nextEvolution)
        {
        case TowerEvolutions.Evolution2:
            towerAnimator.SetBool("EvolvedTo2", true);
            break;

        case TowerEvolutions.Evolution3:
            towerAnimator.SetBool("EvolvedTo3", true);
            break;
        }
    }
Beispiel #2
0
    void OnTriggerEnter2D(Collider2D col)
    {
        if (IsPartOfMasks(col.gameObject.layer, collisionMasks))
        {
            return;
        }

        if (IsPartOfMasks(col.gameObject.layer, targetMasks))
        {
            Health health = col.transform.root.GetComponent <Health>();


            if (health && health.IsAlive())
            {
                MaterialModifier modifier = col.transform.root.GetComponentInChildren <MaterialModifier>();
                if (modifier)
                {
                    modifier.SetTintColor(new Color(1, 0, 0, 1f));
                }

                health.ChangeHealth(-damage);
                CinemachineShake.Instance.ShakeCamera(5, 0.2f);
            }
        }

        GameObject effect = FindObjectsOfType <EffectPooler>()
                            .First(pooler => pooler.effectType == collisionEffectType)
                            .GetPooledObject();

        effect.transform.position = transform.position;
        effect.gameObject.SetActive(true);
        effect.GetComponent <DesactivateObject>().Desactivate(.25f);
        gameObject.SetActive(false);
    }
Beispiel #3
0
 //Tilts material color each 0.2s
 IEnumerator TiltColor()
 {
     while (true)
     {
         modifier.SetTintColor(new Color(1, 1, 1, 1f), 4f);
         yield return(new WaitForSeconds(0.2f));
     }
 }
Beispiel #4
0
    //Event handler for health change
    public void OnPlayerHit()
    {
        MaterialModifier modifier = playerProfile.GetComponent <MaterialModifier>();

        if (modifier)
        {
            modifier.SetTintColor(new Color(1, 0, 0, 1f));
        }
    }
    IEnumerator TiltColor()
    {
        while (true)
        {
            MaterialModifier modifier = GetComponentInChildren <MaterialModifier>();

            modifier.SetTintColor(new Color(1, 1, 1, 1f));
            yield return(new WaitForSeconds(0.2f));
        }
    }
    //Apply explosion effect and cast ripple that deal damage to players inside the radisu
    IEnumerator CastExplosion()
    {
        //This time corresponds to the duration of the explosion animation
        yield return(new WaitForSeconds(.9f));

        GameObject rippleEffect = FindObjectsOfType <EffectPooler>()
                                  .First(pooler => pooler.effectType == EffectType.Shockwave)
                                  .GetPooledObject();

        rippleEffect.transform.position = transform.position;
        rippleEffect.SetActive(true);
        rippleEffect.GetComponent <DesactivateObject>().Desactivate(.45f);
        CinemachineShake.Instance.ShakeCamera(10, 0.25f);

        RaycastHit2D[] explosionHits = Physics2D.CircleCastAll(transform.position, enemySettings.explosionRadius, Vector2.up, enemySettings.explosionRadius, targetsMask);
        foreach (RaycastHit2D hit in explosionHits)
        {
            Health health = hit.transform.GetComponent <Health>();
            if (health && health.IsAlive())
            {
                MaterialModifier modifier = hit.transform.root.GetComponentInChildren <MaterialModifier>();
                if (modifier)
                {
                    modifier.SetTintColor(new Color(1, 0, 0, 1f));
                }
                health.ChangeHealth(-enemySettings.explosionDamage);
            }
        }

        yield return(new WaitForSeconds(0.5f));

        GameManager.Instance.OnMobKilled.Invoke(EnemyType.Slime);


        //Drop Health Potion
        ItemPooler itemPooler = FindObjectsOfType <ItemPooler>().ToList().First(pooler => pooler.itemType == ItemType.Health);

        if (Random.Range(0f, 1f) > 0.5f)
        {
            if (itemPooler != null)
            {
                var healthPotion = itemPooler.GetPooledObject();
                healthPotion.transform.position = transform.position;
                healthPotion.SetActive(true);
            }
        }


        gameObject.SetActive(false);
    }