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

public class ScenarioObject : MonoBehaviour {
    public Action<bool> OnScenarioFinish;
    protected float scenarioTime = 0;
    protected bool finishedScenario = false;

    public virtual void Start() {

    }

    protected virtual void Update() {
        if (finishedScenario) {
            return; }

        scenarioTime += Time.deltaTime;
    }

    protected void OnScenarioWin() {
        OnScenarioFinished();

        if (OnScenarioFinish != null) {
            OnScenarioFinish(true);
        }
    }

    protected void OnScenarioFail() {
        OnScenarioFinished();

        if (OnScenarioFinish != null) {
            OnScenarioFinish(false);
        }
    }

    private void OnScenarioFinished() {
        finishedScenario = true;
        File.AppendAllText(Application.dataPath + "\\times.txt", name + ": " + scenarioTime + "\n");
    }
}
