Exemplo n.º 1
0
    void Explode()
    {
        audioSourse.PlayOneShot(explodeSound);
        print(audioSourse);
        Instantiate(explodeEffect, transform.position, transform.rotation);

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

        foreach (Collider nearbyObject in enemyHealth)
        {
            EnemyHealth   health  = nearbyObject.GetComponent <EnemyHealth>();
            HealthManager healthM = nearbyObject.GetComponent <HealthManager>();

            if (health != null)
            {
                health.EnemyHealthCheck(damage);
            }
            if (healthM != null)
            {
                healthM.Health(damage);
            }
        }

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

        foreach (Collider nearbyObject in colliderToDestroy)
        {
            Rigidbody rb = nearbyObject.GetComponent <Rigidbody>();

            if (rb != null)
            {
                rb.AddExplosionForce(force, transform.position, radius);
            }
        }

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

        foreach (Collider nearbyObject in colliderToMove)
        {
            Rigidbody rb = nearbyObject.GetComponent <Rigidbody>();

            if (rb != null)
            {
                rb.AddExplosionForce(force, transform.position, radius);
            }
        }
        render.enabled = false;
        Destroy(gameObject, 4);
    }