//This method allows the enemies to assign damage to the player public void TakeDamage(int amount) { //If the player isn't alive, leave if (!IsAlive()) { return; } //If the player is not invulnerable, reduce the current health if (!isInvulnerable) { currentHealth -= amount; } //If there is a damage image, tell it to flash if (damageImage != null) { damageImage.Flash(); } //If there is a health slider, update its value if (healthSlider != null) { healthSlider.value = currentHealth / (float)maxHealth; } //If the player has been defeated by this attack... if (!IsAlive()) { //...if there is a player movement script, tell it to be defeated if (playerMovement != null) { playerMovement.Defeated(); } //...if there is a player attack script, tell it to be defeated if (playerAttack != null) { playerAttack.Defeated(); } //...set the Die parameter in the animator animator.SetTrigger("Die"); //...if there is an audio source, assign the deathclip to it if (audioSource != null) { audioSource.clip = deathClip; } //...finally, tell the GameManager that the player has been defeated GameManager.Instance.PlayerDied(); } //If there is an audio source, tell it to play if (audioSource != null) { audioSource.Play(); } }
public void TakeDamage(int amount) { if (!isAlive()) { return; } currentHealth -= amount; damageImage.Flash(); if (!isAlive()) { playerMovement.Defeated(); playerAtack.Defeated(); animator.SetTrigger("Die"); audioSource.clip = deathClip; GameManager.Instance.PlayerDied(); } audioSource.Play(); }
//This method allows the enemies to assign damage to the player public void TakeDamage(int amount) { //If the player isn't alive, leave if (!IsAlive()) { return; } //If the player is not invulnerable, reduce the current health if (!isInvulnerable) { currentHealth -= amount; } //If there is a damage image, tell it to flash if (damageImage != null) { damageImage.Flash(); } //If there is a health slider, update its value if (healthSlider != null) { healthSlider.value = currentHealth / (float)maxHealth; } if (currentHealth <= 50 && IsAlive()) { musicSystem.IsHalfHealth(); } //If the player has been defeated by this attack... if (!IsAlive()) { //...if there is a player movement script, tell it to be defeated if (playerMovement != null) { playerMovement.Defeated(); } //...if there is a player attack script, tell it to be defeated if (playerAttack != null) { playerAttack.Defeated(); } //...set the Die parameter in the animator animator.SetTrigger("Die"); //...if there is an audio source, assign the deathclip to it FMODUnity.RuntimeManager.PlayOneShot(playerDeathSound, transform.position); FMODUnity.RuntimeManager.PlayOneShot(DeathMusic, transform.position); //Play the death music musicSystem.IsDeadMusic(); //...finally, tell the GameManager that the player has been defeated GameManager.Instance.PlayerDied(); } //If there is an audio source, tell it to play FMODUnity.RuntimeManager.PlayOneShot(playerHurtSound, transform.position); }
//此方法允许敌人为玩家分配伤害 //This method allows the enemies to assign damage to the player public void TakeDamage(int amount) { //如果玩家不存在,请离开 //If the player isn't alive, leave if (!IsAlive()) { return; } //如果玩家无敌,请降低当前生命值 //If the player is not invulnerable, reduce the current health if (!isInvulnerable) { currentHealth -= amount; } //如果有损坏的图像,告诉它闪烁 //If there is a damage image, tell it to flash if (damageImage != null) { damageImage.Flash(); } //如果有健康状况滑块,请更新其值 //If there is a health slider, update its value if (healthSlider != null) { healthSlider.value = currentHealth / (float)maxHealth; } //如果玩家已被这次攻击击败... //If the player has been defeated by this attack... if (!IsAlive()) { // ...如果有玩家移动脚本,告诉它被击败 //...if there is a player movement script, tell it to be defeated if (playerMovement != null) { playerMovement.Defeated(); } // ...如果有玩家攻击脚本,告诉它被击败 //...if there is a player attack script, tell it to be defeated if (playerAttack != null) { playerAttack.Defeated(); } // ...在动画器中设置Die参数 //...set the Die parameter in the animator animator.SetTrigger("Die"); // ...如果有音频源,请为其分配死亡片段 //...if there is an audio source, assign the deathclip to it if (audioSource != null) { audioSource.clip = deathClip; } // ...最后,告诉GameManager玩家已被击败 //...finally, tell the GameManager that the player has been defeated GameManager.Instance.PlayerDied(); } //如果有音频源,请告诉它播放 //If there is an audio source, tell it to play if (audioSource != null) { audioSource.Play(); } }