Пример #1
0
    void Explode()
    {
        Instantiate(explosionEffect, transform.position, transform.rotation);

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

        foreach (Collider nearbyObject in collidersToDestroy)
        {
            Destructable dest = nearbyObject.GetComponent <Destructable>();

            if (dest != null)
            {
                dest.Destroy();
            }
        }

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

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

        Destroy(gameObject);
    }
Пример #2
0
    void HouseDestruction()
    {
        //Initially we will make an array which searches through each object that is colliding with the player
        //within the specified bounderies, and then we will call another script in which we destroy the
        //original object and instantiate a broken version, then we search for colliders again, but this
        //time for the new destroyed buildings, and add force to them
        Collider[] collidersToDestroy = Physics.OverlapSphere(transform.position, destructionRadius);

        foreach (Collider nearbyObject in collidersToDestroy)
        {
            Destructable dest = nearbyObject.GetComponent <Destructable>();
            if (dest != null)
            {
                dest.Destroy();
                housesDestroyed++;
            }
        }

        Collider[] collidersToMove = Physics.OverlapSphere(transform.position, destructionRadius);

        foreach (Collider nearbyObject in collidersToMove)
        {
            Rigidbody rb = nearbyObject.GetComponent <Rigidbody>();
            if (rb != null)
            {
                rb.AddExplosionForce(explosionForce, transform.position, destructionRadius);
            }
        }
    }
Пример #3
0
    public void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.tag == Tags.Player && collision.gameObject != owner.gameObject)
        {
            //Hit Player
            TankController tankController = collision.GetComponent <TankController>();
            tankController.HitAndCheckDeath(damage, owner);

            ProjectileDestroy();
        }
        else if (collision.tag == Tags.Desctructable)
        {
            Destructable destructable = collision.gameObject.GetComponent <Destructable>();
            if (owner.photonView.IsMine)
            {
                owner.CurrentAmmo += destructable.AmmoReward;

                owner.OnDestructableDestroy(destructable);
                destructable.Destroy();

                ProjectileDestroy();
            }
        }
    }