Time Manager Class Implementation Like Coroutine in Unity

I required to use multiple coroutines as per my game requirements but I found that its performance hungry. So I decided to write something own using Update method that behave similar to Coroutine in Unity. I can say its TimeManager class for implementation.

Main requirement, at a time I can run multiple instances of this TimeManager class because at many placed within the environment time based activities are running.

In this please give me, just an idea about kind of implementation remains good for me. I will do the code and share for other developers to use.

You can do that, or add a custom timer script component to each object that you want to run a timer, then add a callback to the function you want to call after the timer run out

If you want to use TimeManager, you can try this

    public class FunctionCountdown
    {
        public float timeLeft;
        public Action functionCall;

        public FunctionCountdown(Action functionCall, float timeLeft)
        {
            this.timeLeft = timeLeft;
            this.functionCall = functionCall;
        }

        public void OnUpdate()
        {
            timeLeft -= Time.deltaTime;
            if (timeLeft <= 0f)
            {
                functionCall();
            }
        }
    }
    
    //class TimeManager:
    List<FunctionCountdown> functionList;

    public void AddFunction(Action func, float time) //call this to add function and time to the list
    {
        functionList.Add(new FunctionCountdown(func, time));
    }

    private void Update()
    {
        foreach (var item in functionList)
        {
            item.OnUpdate();
        }
    }