Esempio n. 1
0
    void Explode()
    {
        GameObject spawnedParticle = Instantiate(exploParticle, transform.position, transform.rotation);

        Destroy(spawnedParticle, 1);

        Collider [] collidersToDeatroy = Physics.OverlapSphere(transform.position, radius);

        foreach (Collider nearbyObject in collidersToDeatroy)
        {
            Destructible dest = nearbyObject.GetComponent <Destructible>();
            if (dest != null)
            {
                dest.OnGrenadeExplosion();
                if (dest.towerLifeLevel <= 0)
                {
                    dest.DestroyDestructible();
                }
            }
        }

        Collider [] collidersToPunch = Physics.OverlapSphere(transform.position, radius);
        foreach (Collider nearbyObject in collidersToPunch)
        {
            Rigidbody rb = nearbyObject.GetComponent <Rigidbody>();
            if (rb != null)
            {
                rb.AddExplosionForce(force, transform.position, radius);
            }
        }

        hasExploded = true;
        Destroy(gameObject);
    }