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

public class RunEventSequence : MonoBehaviour
{
    public float elapsedTime;
    public bool timeRunning;

    public GameObject[] sequences;

    public void SetTimeRunning(bool enabled)
    {
        timeRunning = enabled;
    }

    private void Update()
    {
        if (timeRunning)
        {
            elapsedTime += Time.deltaTime;
            int doneSequences = 0;
            for (int i = 0; i < sequences.Length; i++)
            {
                EventSequence seq = sequences[i].GetComponent<EventSequence>();

                if (seq.beenTriggered)
                    doneSequences++;

                if (!seq.beenTriggered && elapsedTime >= seq.timeToTrigger)
                {
                    seq.beenTriggered = true;
                    seq.eventToTrigger.Invoke();
                }
            }

            if (doneSequences == sequences.Length)
                enabled = false;
        }
    }
}