31 lines
544 B
C#
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); }
|
|
}
|
|
}
|
|
}
|
|
}
|