Exemplo n.º 1
0
    void Explosion()
    {
        Collider[] coll = Physics.OverlapSphere(transform.position, Range);
        GameObject p    = Instantiate(ExplosionEffect, transform.position, transform.rotation);

        p.GetComponent <ParticleSystem>().Play();
        AudioSource.PlayClipAtPoint(ExplosionSound, transform.position);
        HashSet <Transform> set = new HashSet <Transform>();

        foreach (var obj in coll)
        {
            if (set.Contains(obj.transform.root))
            {
                continue;
            }
            set.Add(obj.transform.root);
            Tank tank = obj.GetComponent <Tank>();
            if (tank != null)
            {
                tank.AddDamage(CalculateDamge(transform.position, obj.transform));
            }
            Rigidbody rigid = obj.GetComponent <Rigidbody>();
            if (rigid != null)
            {
                rigid.AddExplosionForce(ExplosionForce, transform.position, Range);
            }
        }
        Destroy(this.gameObject);
    }