CapersProject/Assets/02.Scripts/Prop/DamageableProps.cs
Nam Tae Gun 7fe3892d1c #18 GhostBarrel 추가 및 버그 수정
+ GhostBarrel 오브젝트 추가
+ OpaqueLit 재질에서 Receive Shadow를 받고 안받는 재질을 구분
+ 코뿔소 맵에 Maple Leaf 파티클 추가
+ 얼음두지 맵에 Bgm Missing 오류 수정
+ 얼음두지 피격 파티클, Spike Die 파티클 추가
2024-06-28 17:44:52 +09:00

81 lines
2.1 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; }
public bool IsInvincible { get; private set; }
[field: SerializeField]
public float InvincibilityDuration { get; private set; }
[Title("Die 설정")]
[SerializeField]
protected string DieSfxName;
[SerializeField]
protected ParticleSystem DieParticle;
protected Transform SpawnLocation;
protected virtual void OnEnable()
{
SetCurrentHealthPoint(MaxHealthPoint);
}
public virtual void SetCurrentHealthPoint(int changedHealthPoint)
{
CurrentHealthPoint = changedHealthPoint;
}
public virtual bool CanDamage()
{
return CurrentHealthPoint > 0;
}
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)
{
var dieParticleInstance = Instantiate(DieParticle, transform.position, DieParticle.transform.rotation, SpawnLocation);
dieParticleInstance.Play();
}
Destroy(gameObject);
}
}
}