using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public abstract class CustomLoop : MonoBehaviour
{
    public static bool Run { get { return s_run; } set { s_run = value; } }
    private static bool s_run = true;
    private Coroutine m_loop;

    private void OnEnable()
    {
        m_loop = StartCoroutine(InternalUpdate());
    }

    private void OnDisable()
    {
        StopCoroutine(m_loop);
    }

    protected abstract void PausableUpdate();

    private IEnumerator InternalUpdate()
    {
        while (true)
        {
            if (Run)
            {
                PausableUpdate();
            }
            yield return null;
        }
    }
}
