using UnityEngine.Events;

[System.Serializable]
public class Ticker
{
    public float interval;
    public float tick;

    public UnityEvent onTick = new UnityEvent();

    public Ticker() { }
    public Ticker(float interval) { this.interval = interval; }
    public Ticker(float interval, float delay) { this.interval = interval; this.tick = -delay; }

    public void Tick(float timeDelta)
    {
        tick += timeDelta;

        if (tick >= interval)
        {
            tick -= interval;
            if (onTick != null) onTick.Invoke();
        }
    }
}