﻿using UnityEngine;
using System.Collections;

public abstract class Platform : MonoBehaviour {

    public bool _key = false;
    private float lastEventTrigger = 0;

    public int id;

    [SerializeField]
    public float eventTime = 1;

    public void Activate() {
        Key = !Key;
    }

    public bool Key
    {
        get
        {
            return _key;
        }

        set
        {
            float curTime = Time.time;

            if( (curTime - lastEventTrigger) > eventTime || lastEventTrigger == 0)
            {
                lastEventTrigger = curTime;
                _key = value;
            }
        }
    }

    public void Update()
    {
        UpdateKey();
        if (_key)
        {
            Action();
            _key = false;
            lastEventTrigger = Time.time;
        }
    }

    public abstract void Action();
    public abstract void UpdateKey();

}
