private void Explode()
    {
        if (_timeBombState != TimeBombState.ACTIVATED)
        {
            return;
        }

        _timeBombState = TimeBombState.DETONATED;

        EnableActivateParticles(true);

        Vector3 explosionPos = transform.position;

        Collider[] colliders = Physics.OverlapSphere(explosionPos, _radius);
        foreach (Collider col in colliders)
        {
            Rigidbody rb = col.GetComponent <Rigidbody>();
            if (rb != null)
            {
                if (rb.CompareTag("DonutTruck"))
                {
                    SCR_TruckDestructionManager truckDestrManager = col.GetComponent <SCR_TruckDestructionManager>();

                    // Calc damage
                    Vector3 truckPos = rb.position;
                    float   distance = (explosionPos - truckPos).magnitude;
                    float   damage   = (distance / _radius) * _maxDamage;

                    truckDestrManager.TakeDamage(damage);

                    rb.AddExplosionForce(_strength * _truckStrengthMultiplier, explosionPos, _radius);
                }
                else if (!rb.CompareTag("PoliceCar"))
                {
                    rb.AddExplosionForce(_strength, explosionPos, _radius);
                    _SoundHolder.GetComponent <SCR_AudioManager>().PlaySound(_SoundHolder.GetComponent <SCR_AudioManager>().GetSoundEffects()[9], GameObject.FindWithTag("PoliceCar"));
                }
            }
        }
    }
Пример #2
0
 void Start()
 {
     _DestructionManager = GameObject.FindGameObjectWithTag("DonutTruck").GetComponent <SCR_TruckDestructionManager>();
 }