Example #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);

            TankShooting targetShooting = targetRigidbody.GetComponent <TankShooting> ();

            TankManager tankManager = GameManager.m_Instance.FindTankManager(m_PlayerNumber);

            if (tankManager.m_TankObject.m_PlayerNumber == targetShooting.m_PlayerNumber)
            {
                tankManager.SubPoints((int)damage);
            }
            else
            {
                tankManager.AddPoints((int)damage);
            }

            targetHealth.TakeDamage(damage);
        }

        Rigidbody bombRigidbody = other.GetComponent <Rigidbody> ();

        if (bombRigidbody)
        {
            return;
        }

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


        Destroy(m_ExplosionParticles.gameObject, m_ExplosionParticles.main.duration);
        Destroy(gameObject);
    }