There is a limited list of possible events (actions). When and in what sequence they will occur is not known in advance. An event has a certain execution time (3 seconds). If two or more events occur simultaneously (or within less than 3 seconds), then the next event would wait for the previous one to form, forming a conditional queue.

Those. If during the interval of less than 3 seconds, events of 1.3 occurred, and 7, then you need to start the event 1 to start, wait for 3 seconds, event 3, wait for 3 seconds, event 7

How can this be done at all? Coroutine doesn’t fit as I understood after the initialization of the korutin is "blocked" and cannot receive new variables (those if we initialized coroutine with events 1 and 3 and then (after initialization but before execution) event 7 occurred - then this very event 7 is lost or launch a new korutinu on top of already working)

All that comes to my mind is to have in Update () a dynamically cleared Array or List where actions will be recorded and from where they will be taken every 3 seconds for execution ... But this is somehow very cumbersome and I would not like to climb in Update () .

Is it possible to implement this task as it is easier?

    1 answer 1

    I would implement it like the Observer pattern. Made a general class that remembers who needs to respond to events, and made methods for subscribing to events, triggering an event, and returning after an event has ended. Thus, you make a list of events as they occur, where you register event processing from third-party classes via a subscription, and you start the order of execution only after the object processing the event responds that the event has completed. Thus, your events will be handled independently of the Update and easily configured. I did something similar, but without waiting for the completion of events.