Пример #1
0
    //Called when health drops down to 0
    IEnumerator OnDeath()
    {
        if (isDead)
        {
            yield break;
        }
        isDead = true;
        StartCoroutine(TiltColor());
        GameObject sfxInstance = FindObjectsOfType <EffectPooler>()
                                 .First(pooler => pooler.effectType == deathSFX)
                                 .GetPooledObject();

        sfxInstance.transform.position = transform.position;
        sfxInstance.SetActive(true);

        yield return(new WaitForSeconds(1f));

        sfxInstance.SetActive(false);

        GameManager.Instance.OnMobKilled.Invoke(EnemyType.Tower);
        //Drop Timer Powerup
        ItemPooler itemPooler = FindObjectsOfType <ItemPooler>().ToList().First(pooler => pooler.itemType == ItemType.TimerAddOn);

        if (itemPooler != null)
        {
            var item = itemPooler.GetPooledObject();
            item.transform.position = transform.position;
            item.SetActive(true);
        }
        gameObject.SetActive(false);
    }
Пример #2
0
    //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);
    }