Beispiel #1
0
    IEnumerator ExplodeCoroutine(bool doubleRadius = false)
    {
        inExplodeCoroutine = true;

        if (GameManager.S.inGame)
        {
            SoundManager.instance.Play("BombExplode");
            SoundManager.instance.Play("Explosion");
        }
        hasExploded    = true;
        hitbox.enabled = false;
        GetComponent <SpriteRenderer>().enabled = false;
        GetComponentInChildren <ParticleSystem>().Play();
        Destroy(gameObject, 2.5f);

        Collider[]    allObjectsHit    = Physics.OverlapSphere(transform.position, (doubleRadius ? 2 : 1) * explosionRadius);
        ProximityMine nearestOtherMine = null;

        foreach (var obj in allObjectsHit)
        {
            //If any players are within the blast zone
            if (obj.gameObject.tag == "Player")
            {
                //Ignore the mine's owner
                Ship shipHit = obj.gameObject.GetComponentInParent <Ship>();
                if (shipHit.playerEnum == owningPlayer)
                {
                    continue;
                }
                //Deal damage to any other player
                else
                {
                    shipHit.TakeDamage(flatDamage);
                }
            }
            //Deal damage to any protag ship caught in the explosion
            else if (obj.gameObject.tag == "ProtagShip")
            {
                ProtagShip shipHit = obj.gameObject.GetComponentInParent <ProtagShip>();
                shipHit.TakeDamage(flatDamage);
            }
            //Blow up any other nearby proximity mines, with twice the radius (more mines == bigger explosion)
            else if (obj.gameObject.tag == "ProximityMine")
            {
                if (nearestOtherMine == null)
                {
                    nearestOtherMine = obj.gameObject.GetComponent <ProximityMine>();
                }
            }
        }

        if (nearestOtherMine != null)
        {
            yield return(new WaitForSeconds(otherMineDetonationDelay));

            nearestOtherMine.Explode(true);
        }

        inExplodeCoroutine = false;
    }
Beispiel #2
0
    private void Explode()
    {
        //start explosion
        exploding = true;
        Instantiate(explosion, transform.position, transform.rotation);
        Destroy(this.gameObject);


        //gets all of the collider's within the exoplosion's range
        Collider[] hitColliders = Physics.OverlapSphere(transform.position, globalProximityRadius);
        for (int i = 0; i < hitColliders.Length; i++)
        {
            //kill player if in range
            if (hitColliders[i].tag == "Player")
            {
                Vector3    collisionPosition = hitColliders[i].transform.position;
                Quaternion collisionRotation = Quaternion.LookRotation(hitColliders[i].transform.up);

                /*
                 * if (!PlayerInformation.instance.dead)
                 * {
                 *  PlayerInformation.instance.PlayerDeath(collisionPosition, collisionRotation);
                 * }*/
            }

            //sets off chain reaction of mine explosions if they are within the blast radius
            if (hitColliders[i].tag == "Mine" && (hitColliders[i].gameObject.name != this.gameObject.name))
            {
                ProximityMine pm = hitColliders[i].gameObject.GetComponent <ProximityMine>();
                if (pm.exploding == false)
                {
                    pm.Explode();
                }
            }
        }


        //gets all of the collider's within the force distance range to add explosion force to them
        float globalForceRadius = proximityCollider.transform.lossyScale.x * (forceRadius);

        Collider[] forceColliders = Physics.OverlapSphere(transform.position, globalForceRadius);
        for (int i = 0; i < forceColliders.Length; i++)
        {
            //gets parent rigid body
            Rigidbody rb = forceColliders[i].transform.root.gameObject.GetComponent <Rigidbody>();
            if (rb != null && (forceColliders[i].gameObject.name != this.gameObject.name))
            {
                rb.AddExplosionForce(explosionForce, transform.position, globalForceRadius, 1f, ForceMode.Impulse);
            }
        }
    }