ノックバックアニメーション追加
This commit is contained in:
@@ -6,13 +6,13 @@ public class EnemyHealth : MonoBehaviour, IDamageble
|
||||
[SerializeField] private float maxHealth = 100f;
|
||||
private float currentHealth;
|
||||
|
||||
[SerializeField] private float knockbackForce = 5f;
|
||||
private Rigidbody rb;
|
||||
[SerializeField] private float knockbackDuration = 0.5f;
|
||||
private EnemyAI enemyAI;
|
||||
|
||||
void Start()
|
||||
{
|
||||
currentHealth = maxHealth; //HPを代入
|
||||
rb = GetComponent<Rigidbody>();
|
||||
enemyAI = GetComponent<EnemyAI>();
|
||||
}
|
||||
|
||||
public void TakeDamage(DamageInfo damageInfo)
|
||||
@@ -26,19 +26,26 @@ public class EnemyHealth : MonoBehaviour, IDamageble
|
||||
Debug.Log("構えボーナス");
|
||||
}
|
||||
|
||||
if(rb != null) //ノックバック
|
||||
{
|
||||
rb.AddForce(damageInfo.punchDirection * knockbackForce, ForceMode.Impulse); //パンチが飛んできた方向に力を加える
|
||||
}
|
||||
|
||||
if(currentHealth <= 0)
|
||||
{
|
||||
Die();
|
||||
}
|
||||
else
|
||||
{
|
||||
if(enemyAI != null)
|
||||
{
|
||||
enemyAI.TriggerKnockback(knockbackDuration);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void Die()
|
||||
{
|
||||
if(enemyAI != null)
|
||||
{
|
||||
enemyAI.DisableAIOnDeath();
|
||||
}
|
||||
|
||||
Destroy(gameObject, 0.5f);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user