Exemplo n.º 1
0
    public void Explode()
    {
        if (m_triggered)
        {
            return;
        }

        m_triggered = true;

        InstantiateExplosion(transform.position);
        InstantiateFireAndSmoke(transform.position);

        if (m_enemyHealthScript != null)
        {
            m_enemyHealthScript.AddFireAndSmoke(m_activeFireAndSmoke);
        }

        var colliders = Physics.OverlapSphere(transform.position, m_explosionChainReactionRadius);

        for (int i = 0; i < colliders.Length; i++)
        {
            var collider         = colliders[i];
            var explosionTrigger = collider.GetComponent <ExplosionTrigger>();
            var healthScript     = collider.GetComponentInParent <EnemyHealth>();

            if (explosionTrigger != null)
            {
                float distance = (transform.position - collider.transform.position).magnitude;
                float delay    = m_explosionChainReactionMaxDelay * distance / m_explosionChainReactionRadius;

                StartCoroutine(TriggerNearbyExplosions(explosionTrigger, delay));
            }

            if (healthScript != null)
            {
                float distance = (transform.position - collider.transform.position).magnitude;
                float delay    = m_explosionChainReactionMaxDelay * distance / m_explosionChainReactionRadius;

                StartCoroutine(DamageNearbyObjects(healthScript, delay));
            }
        }
    }