Files
beyond/Assets/AI/Common/DelayedInvoker.cs
SzymonMis 06f9c7349d Summoner
2026-02-19 21:34:07 +01:00

31 lines
544 B
C#

using System;
using UnityEngine;
namespace DemonBoss.AI
{
/// <summary>
/// Tiny helper MonoBehaviour to delay a callback without coroutines.
/// </summary>
public sealed class DelayedInvoker : MonoBehaviour
{
private float _timeLeft;
private Action _callback;
public void Init(float delay, Action callback)
{
_timeLeft = delay;
_callback = callback;
}
private void Update()
{
_timeLeft -= Time.deltaTime;
if (_timeLeft <= 0f)
{
try { _callback?.Invoke(); }
finally { Destroy(this); }
}
}
}
}