CapersProject/Assets/02.Scripts/Prop/DamageableProps.cs
Nam Tae Gun 4db6c2bf57 #17 모래두더지 구르기 스킬(SingleRoll) 추가
+ BaseSkillData에서 TargetLayer를 받아오게끔 로직 수정(스킬마다의 Target이 다름)
+ DamageableProps 태그 추가
+ DamageableProps 부모 클래스 추가
+ DamageableProps 상속 클래스 Rockfall 추가
+ SandMole(모래두더지)가 벽에 박치기 한 뒤에 Rockfall(낙석)을 떨어뜨리는 기능 추가
2024-06-14 18:11:35 +09:00

70 lines
1.7 KiB
C#

using BlueWater.Audios;
using BlueWater.Interfaces;
using Sirenix.OdinInspector;
using UnityEngine;
namespace BlueWater
{
public class DamageableProps : MonoBehaviour, IDamageable
{
[field: Title("체력")]
[field: SerializeField]
public int MaxHealthPoint { get; private set; } = 1;
[field: SerializeField]
public int CurrentHealthPoint { get; private set; }
[Title("Die 설정")]
[SerializeField]
private string _dieSfxName;
[SerializeField]
private ParticleSystem _dieParticle;
protected Transform SpawnLocation;
public virtual void SetCurrentHealthPoint(int changedHealthPoint)
{
CurrentHealthPoint = changedHealthPoint;
}
public virtual bool CanDamage()
{
return true;
}
public virtual void TakeDamage(int damageAmount)
{
var changeHp = Mathf.Max(CurrentHealthPoint - damageAmount, 0);
SetCurrentHealthPoint(changeHp);
if (changeHp == 0f)
{
Die();
return;
}
}
public virtual void TryTakeDamage(int damageAmount)
{
if (!CanDamage()) return;
TakeDamage(damageAmount);
}
public virtual void Die()
{
if (!string.IsNullOrEmpty(_dieSfxName))
{
AudioManager.Instance.PlaySfx(_dieSfxName);
}
if (_dieParticle && SpawnLocation)
{
Instantiate(_dieParticle, transform.position, Quaternion.identity, SpawnLocation);
}
Destroy(gameObject);
}
}
}