Ejemplo n.º 1
0
    void OnCollisionEnter(Collision other)
    {
        if (other.gameObject.layer == 9 || other.gameObject.layer == 12) //Boundaries and Ground Layers
        {
            Destroy(gameObject);
        }
        if (other.gameObject.layer == 10) //Enemy Layer
        {
            //Deal Damage
            EnemyHealth enemyHealthScript = other.gameObject.GetComponent <EnemyHealth>();
            enemyHealthScript.health -= damage;

            //Knockback
            EnemyDetectionMovement EDM = other.gameObject.GetComponent <EnemyDetectionMovement>();
            EDM.Knockback(knockback, gameObject, true);

            //BloodParticles
            bloodsplatter.DoBloodSplatter(other.gameObject.transform);

            //Hurt Sound (has to be the second audio source in the enemy's inspector).
            AudioSource[] enemyHurtSound = other.gameObject.GetComponents <AudioSource>();
            enemyHurtSound[1].Play();

            //Destroy self (instantiated bullet)
            Destroy(gameObject);
        }
    }
Ejemplo n.º 2
0
    //Explosion damage calculations for a character.
    void DealExplosionDamage(Collider nearbyObject, EnemyHealth healthScript = null)
    {
        float distance = Vector3.Distance(transform.position, nearbyObject.transform.position);

        //Player Calculations
        if (healthScript == null)
        {
            if (distance > 4.5f)
            {
                PlayerHealth.health -= 25;
            }
            else if (distance <= 4.5f && distance > 4)
            {
                PlayerHealth.health -= 50;
            }
            else if (distance <= 4 && distance > 3.5f)
            {
                PlayerHealth.health -= 75;
            }
            else if (distance <= 3.5f)
            {
                PlayerHealth.health -= 100;
            }

            //SoundEffect
            FindObjectOfType <AudioManager>().Play("PlayerHurt");
        }

        //Enemy calculations
        else
        {
            if (distance > 4.5f)
            {
                healthScript.health -= 25;
            }
            else if (distance <= 4.5f && distance > 4)
            {
                healthScript.health -= 50;
            }
            else if (distance <= 4 && distance > 3.5f)
            {
                healthScript.health -= 75;
            }
            else if (distance <= 3.5f)
            {
                healthScript.health -= 100;
            }

            //Hurt Sound (has to be the second audio source in the enemy's inspector).
            AudioSource[] enemyHurtSound = nearbyObject.gameObject.GetComponents <AudioSource>();
            enemyHurtSound[1].Play();
        }

        //Blood Particles
        bloodsplatter.DoBloodSplatter(nearbyObject.gameObject.transform);
    }
Ejemplo n.º 3
0
    //Deals damage, knockback, and instantiates blood particles
    void DoMeleeHit()
    {
        //Deal Damage
        EH.health -= damage;

        //Knockback
        EDM.Knockback(knockback, gameObject);

        //BloodParticles
        bloodsplatter.DoBloodSplatter(enemyLocation);

        //Hurt Sound (has to be the second audio source in the enemy's inspector).
        enemyHurtSound[1].Play();
    }
Ejemplo n.º 4
0
    void DealDamage(Collider other)
    {
        //Deal Damage
        PlayerHealth.health -= damage;
        meleeIsOnCooldown    = true;

        //Knockback
        ImpactReceiver IR        = other.GetComponent <ImpactReceiver>();
        Vector3        direction = (other.transform.position - transform.position).normalized;

        IR.AddImpact(direction, knockbackForce);

        //BloodParticles
        bloodsplatter.DoBloodSplatter(other.gameObject.transform);

        //SoundEffect
        FindObjectOfType <AudioManager>().Play("PlayerHurt");

        //Animation
        attackAnim.SetBool("isAttacking", true);
    }