private void OnTriggerEnter(Collider other) { if (other.tag == "Player") { PlayerHealth hp = other.gameObject.GetComponent <PlayerHealth>(); if (hp.currentHealth != 100) { hp.Heal(restoreAmount); Destroy(this.gameObject); } } }
void Death() { // The enemy is dead. isDead = true; // Turn the collider into a trigger so shots can pass through it. capsuleCollider.isTrigger = true; // Tell the animator that the enemy is dead. anim.SetTrigger("Dead"); // Change the audio clip of the audio source to the death clip and play it (this will stop the hurt clip playing). enemyAudio.clip = deathClip; enemyAudio.Play(); //Heal the player when die playerHealth.Heal(heal); }