Пример #1
0
    private void OnCollisionEnter(Collision collision)
    {
        //////////////////////////////
        // HIT ENEMY
        //////////////////////////////

        if (collision.gameObject.tag == "Enemy" && isDashing && dashDamageTimer > 0.07f)
        {
            if (collision.gameObject.GetComponent <Enemy>().health - dashDamage <= 0 &&
                collision.gameObject.GetComponent <Enemy>().ableToBeDamaged == true)
            {
                collision.gameObject.GetComponent <Enemy>().Damage(dashDamage, dashKnockback);
                collision.gameObject.tag = "Untagged";
                Destroy(collision.gameObject.GetComponent <Enemy>());
                Destroy(collision.gameObject.GetComponent <Animator>());
                Destroy(collision.gameObject.GetComponent <BoxCollider>());
                Destroy(collision.gameObject.GetComponent <UnityEngine.AI.NavMeshAgent>());
                KillParent(collision.transform);
                trashCollector.AddToTrash(collision.gameObject);

                ChangeDashingState(0);
            }
            else
            {
                collision.gameObject.GetComponent <Enemy>().Damage(dashDamage, dashKnockback);
            }
        }
    }
Пример #2
0
    public void Explode()
    {
        if (hasExploded == true)
        {
            return;
        }

        if (hasStages == true)
        {
            currentHealth--;
            if (currentHealth <= 0)
            {
                timesHit++;
                currentHealth = healthPerStage;
            }
            else
            {
                return;
            }


            if (timesHit < stages.Count)
            {
                stages[timesHit - 1].SetActive(false);
                stages[timesHit].SetActive(true);
            }
            else
            {
                hasExploded = true;
                KillParent(stages[timesHit - 1].transform);

                foreach (DestructableObject obj in destructableChildren)
                {
                    if (obj.hasExploded == false)
                    {
                        obj.InstaExplode();
                    }
                }

                foreach (Transform trans in children)
                {
                    if (trans != null)
                    {
                        if (trans.parent.gameObject.activeSelf == true)
                        {
                            trashCollector.AddToTrash(trans.gameObject);
                        }
                    }
                }
            }
        }
        else
        {
            currentHealth--;
            if (currentHealth > 0)
            {
                return;
            }

            hasExploded = true;
            foreach (Transform trans in children)
            {
                if (trans != null)
                {
                    trashCollector.AddToTrash(trans.gameObject);
                }
            }

            KillParent(transform);
        }
    }