Exemple #1
0
    private void OnTriggerEnter(Collider other)
    {
        Collider[] colliders = Physics.OverlapSphere(transform.position, m_ExplosionRadius, m_TankMask);

        for (int i = 0; i < colliders.Length; i++)
        {
            Rigidbody targetRigidbody = colliders [i].GetComponent <Rigidbody> ();

            if (!targetRigidbody)
            {
                continue;
            }
            targetRigidbody.AddExplosionForce(m_ExplosionForce, transform.position, m_ExplosionRadius);
            TankLife targetHealth = targetRigidbody.GetComponent <TankLife> ();
            if (!targetHealth)
            {
                continue;
            }
            float damage = CalculateDamage(targetRigidbody.position);

            targetHealth.TakeDamage(damage);
        }

        m_ExplosionParticles.transform.parent = null;
        m_ExplosionParticles.Play();
        m_ExplosionAudio.Play();
        var main = m_ExplosionParticles.main;

        Destroy(m_ExplosionParticles.gameObject, main.duration);
        Destroy(gameObject);
    }
Exemple #2
0
    void Explode()
    {
        GameObject explosion = Instantiate(shellExplosion, transform.position, transform.rotation) as GameObject;

        Collider[] colliders = Physics.OverlapSphere(transform.position, explosionRadius);

        foreach (var c in colliders)
        {
            //Debug.Log("Collider found in explosion radius: " + c.gameObject.name);
            if (c.gameObject.tag == "Player" || c.gameObject.tag == "Enemy")
            {
                Rigidbody rb = c.GetComponent <Rigidbody>();
                rb.AddExplosionForce(explosionForce, transform.position, explosionRadius);
                float damage = damageCalc(rb.position);
                Debug.Log("damage done: " + damage.ToString());
                TankLife hp = c.gameObject.GetComponent <TankLife>();
                hp.TakeDamage(damage);
            }
        }

        Destroy(explosion, 1.5f);
    }