예제 #1
0
    private void OnTriggerEnter(Collider other)
    {
        // Find all the tanks in an area around the shell and damage them.
        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);

            TankHealth targetHealth = targetRigidbody.GetComponent <TankHealth>();

            if (!targetHealth)
            {
                continue;
            }

            float damage = CalculateDamage(targetRigidbody.position);
            targetHealth.TakeDamage(damage);

            if (targetHealth.m_Score != m_Score)
            {
                m_Score.AddDamageDone(damage);
                if (targetHealth.IsDead())
                {
                    m_Score.AddKill();
                }
            }
        }

        m_ExplosionParticles.Play();
        m_ExplosionAudio.Play();

        GetComponent <Rigidbody>().velocity         = new Vector3(0f, 0f, 0f);
        GetComponent <Rigidbody>().detectCollisions = false;
        GetComponent <MeshRenderer>().enabled       = false;
        GetComponent <Light>().enabled = false;

        Destroy(gameObject, m_ExplosionParticles.main.duration);
    }
예제 #2
0
 public bool IsDead()
 {
     return(m_Health.IsDead());
 }