Пример #1
0
    protected virtual void OnCollisionEnter(Collision other)
    {
        ParticleSystem hitParticles = Instantiate(hitParticlesPrefab, other.contacts [0].point, hitParticlesPrefab.transform.rotation) as ParticleSystem;

        hitParticles.Play();
        Destroy(hitParticles.gameObject, 0.3f);


        EnemyHealth enemyHealth = other.collider.GetComponent <EnemyHealth> ();

        if (enemyHealth != null)
        {
            // Special cases
            if (enemyHealth.enemyName == "ZomBear" && bulletName == "Pulse Rifle")
            {
                enemyHealth.TakeDamage(damagePerShot / 3);                // ZomBear has resistance to pulse rifle
            }
            else if (enemyHealth.enemyName == "AttackBot" && (bulletName == "Assault Rifle" || bulletName == "Revolver"))
            {
                enemyHealth.TakeDamage(damagePerShot / 2);                // AttackBot has resistance to mechanical bullets
            }
            else
            {
                enemyHealth.TakeDamage(damagePerShot);
            }

            BulletTracker.AmmoHit(this);
        }


        Destroy(gameObject);
    }
Пример #2
0
    void OnParticleCollision(GameObject other)
    {
        int numCollisionEvents = bulletParticleSystem.GetCollisionEvents(other, collisionEvents);

        if (numCollisionEvents > 0)
        {
            ParticleSystem hitParticles = Instantiate(hitParticlesPrefab, collisionEvents[0].intersection, hitParticlesPrefab.transform.rotation) as ParticleSystem;
            hitParticles.Play();
            Destroy(hitParticles.gameObject, 0.3f);
        }

        EnemyHealth enemyHealth = other.GetComponent <EnemyHealth> ();

        if (enemyHealth != null)
        {
            enemyHealth.TakeDamage(damagePerShot);
            BulletTracker.AmmoHit(this);
        }
    }
Пример #3
0
    public void Explode()
    {
        explosionAudio.Play();
        explosionParticles.Play();

        bool enemyHit = false;

        Collider[] hitColliders = Physics.OverlapSphere(transform.position, explosionRadius);
        int        i            = 0;

        while (i < hitColliders.Length)
        {
            EnemyHealth_Hellephant hellephantHealth = hitColliders[i].GetComponent <EnemyHealth_Hellephant> ();
            if (hellephantHealth != null && !hitColliders[i].isTrigger)
            {
                if (!hellephantHealth.IsSecondForm())
                {
                    hellephantHealth.TakeDamage(explosionDamage);
                    enemyHit = true;
                }
            }
            else
            {
                EnemyHealth enemyHealth = hitColliders[i].GetComponent <EnemyHealth> ();
                if (enemyHealth != null && !hitColliders[i].isTrigger)
                {
                    enemyHealth.TakeDamage(explosionDamage);
                    enemyHit = true;
                }
            }
            i++;
        }

        if (enemyHit)
        {
            BulletTracker.AmmoHit("Grenade Launcher");
        }

        Destroy(gameObject, 5f);
    }