Exemplo n.º 1
0
    private void OnCollisionEnter(Collision collision)
    {
        if (collision.gameObject.tag == "Tank")
        {
            Collider[] TankColliders = Physics.OverlapSphere(transform.position, ExplosionRadius, TankMask);

            foreach (Collider C in TankColliders)
            {
                Rigidbody TargetBody = C.GetComponent <Rigidbody>();

                if (!TargetBody)
                {
                    continue;
                }

                TankHealth Tank = TargetBody.GetComponent <TankHealth>();

                if (!Tank)
                {
                    continue;
                }

                //Calculate FinalForce To Apply
                float FinalForce = BaseForce + Tank.GetVulnerability() * AddedForce;

                //Apply ExplosionForce
                TargetBody.AddExplosionForce(FinalForce, transform.position, ExplosionRadius);

                //Add Vulnerability To Tank
                Tank.AddVulnerability();
            }

            // Unparent the particles from the shell.
            ExplosionParticle.transform.rotation = Quaternion.identity;
            ExplosionParticle.transform.parent   = null;

            // Play the particle system.
            ExplosionParticle.Play();

            ParticleSystem.MainModule MainModule = ExplosionParticle.main;
            Destroy(ExplosionParticle.gameObject, MainModule.duration);

            //Destroy Bullet
            Destroy(gameObject);
        }
    }