EerieVillage/Assets/Scripts/Skills/Effectors/FxAutoDestroyUnscaled.cs

38 lines
1.2 KiB
C#

using UnityEngine;
namespace EerieVillage.Skills.Effectors
{
/// <summary>
/// PD 지시 2026-05-13 — fx GO 영역 unscaledTime 영역 자가 Destroy.
/// Object.Destroy(go, t) 영역 second timer 영역 Time.timeScale 영향 영역 → timeScale=0 (LevelUp 등) 영역 호출 정지·잔존.
/// 본 컴포넌트 = Update 영역 Time.unscaledTime 영역 lifetime check → 자가 Destroy.
/// fxGo Instantiate 직후 AddComponent 영역 lifetime 설정.
/// </summary>
public class FxAutoDestroyUnscaled : MonoBehaviour
{
public float Lifetime = 5f;
float _spawnTime;
void Awake()
{
_spawnTime = Time.unscaledTime;
}
void Update()
{
if (Time.unscaledTime - _spawnTime >= Lifetime)
{
Destroy(gameObject);
}
}
public static void Attach(GameObject go, float lifetime)
{
if (go == null) return;
var c = go.GetComponent<FxAutoDestroyUnscaled>();
if (c == null) c = go.AddComponent<FxAutoDestroyUnscaled>();
c.Lifetime = Mathf.Max(0.1f, lifetime);
}
}
}