45 lines
997 B
C#
45 lines
997 B
C#
using System;
|
|
using UnityEngine;
|
|
|
|
public class EnemyHealth : MonoBehaviour, IDamageble
|
|
{
|
|
[SerializeField] private float maxHealth = 100f;
|
|
private float currentHealth;
|
|
|
|
[SerializeField] private float knockbackForce = 5f;
|
|
private Rigidbody rb;
|
|
|
|
void Start()
|
|
{
|
|
currentHealth = maxHealth; //HPを代入
|
|
rb = GetComponent<Rigidbody>();
|
|
}
|
|
|
|
public void TakeDamage(DamageInfo damageInfo)
|
|
{
|
|
if(currentHealth <= 0) return;
|
|
|
|
currentHealth -= damageInfo.amount; //ダメージ計算
|
|
|
|
if(damageInfo.isPoseBonus)
|
|
{
|
|
Debug.Log("構えボーナス");
|
|
}
|
|
|
|
if(rb != null) //ノックバック
|
|
{
|
|
rb.AddForce(damageInfo.punchDirection * knockbackForce, ForceMode.Impulse); //パンチが飛んできた方向に力を加える
|
|
}
|
|
|
|
if(currentHealth <= 0)
|
|
{
|
|
Die();
|
|
}
|
|
}
|
|
|
|
private void Die()
|
|
{
|
|
Destroy(gameObject, 0.5f);
|
|
}
|
|
}
|