Beispiel #1
0
    //warning: big boi spagaettii kode up ahead (or should i say down)
    public IEnumerator TimerCoroutine()
    {
        while (true)
        {
            TimedAction currentAction = null;
            float       zeroTime      = Time.time;

            while (true)
            {
                foreach (TimedAction action in actions)
                {
                    if (Time.time > zeroTime + action.waitTime && action.test())
                    {
                        currentAction = action;
                        break;
                    }
                }
                if (currentAction != null)
                {
                    break;
                }
                if (passiveWait == 0)
                {
                    yield return(new WaitForEndOfFrame());
                }
                else
                {
                    yield return(new WaitForSeconds(passiveWait));
                }
            }
            currentAction.action();
            yield return(new WaitForSeconds(currentAction.cooldown));
        }
    }