2026-04-08 스킬시스템 진행중, 폴더구조 변경등
This commit is contained in:
61
Assets/02_Scripts/Skill/Effects/ZoneEntity.cs
Normal file
61
Assets/02_Scripts/Skill/Effects/ZoneEntity.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class ZoneEntity : MonoBehaviour
|
||||
{
|
||||
private float _damage;
|
||||
private float _radius;
|
||||
private float _duration;
|
||||
private float _tickInterval;
|
||||
private DebuffData[] _debuffs;
|
||||
|
||||
private float _lifeTimer;
|
||||
private float _tickAccumulator;
|
||||
|
||||
public void Init(float damage, float radius, float duration, float tickInterval, DebuffData[] debuffs)
|
||||
{
|
||||
_damage = damage;
|
||||
_radius = radius;
|
||||
_duration = duration;
|
||||
_tickInterval = tickInterval > 0 ? tickInterval : 1f;
|
||||
_debuffs = debuffs;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
_lifeTimer += Time.deltaTime;
|
||||
_tickAccumulator += Time.deltaTime;
|
||||
|
||||
if (_tickAccumulator >= _tickInterval)
|
||||
{
|
||||
_tickAccumulator -= _tickInterval;
|
||||
ApplyTickDamage();
|
||||
}
|
||||
|
||||
if (_lifeTimer >= _duration)
|
||||
{
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
private void ApplyTickDamage()
|
||||
{
|
||||
Collider[] hits = Physics.OverlapSphere(transform.position, _radius);
|
||||
foreach (Collider col in hits)
|
||||
{
|
||||
IDamageable target = col.GetComponent<IDamageable>();
|
||||
if (target == null) continue;
|
||||
|
||||
target.TakeDamage(Mathf.RoundToInt(_damage), transform);
|
||||
|
||||
if (_debuffs != null)
|
||||
{
|
||||
StatusEffectReceiver receiver = col.GetComponent<StatusEffectReceiver>();
|
||||
if (receiver != null)
|
||||
{
|
||||
foreach (var debuff in _debuffs)
|
||||
receiver.ApplyDebuff(debuff);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user