攻撃できるようになりました
This commit is contained in:
44
Assets/Scripts/EnemyHealth.cs
Normal file
44
Assets/Scripts/EnemyHealth.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user