示例#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);
        }
    }
示例#2
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();
    }