using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Events;

public class ButtonInteraction : MonoBehaviour
{
    public Image loadingImage;
    public UnityEvent buttonClick;
    public float totalTime = 2;
    bool status;
    public float timer;

    // Update is called once per frame
    void Update()
    {
        if(status)
        {
            timer += Time.deltaTime;
            loadingImage.fillAmount = timer / totalTime;
        }

        if (timer > totalTime)
        {
            timer = 0;
            buttonClick.Invoke();
        }
    }

    public void Activated()
    {
        status = true;
    }

    public void Deactivated()
    {
        status = false;
        timer = 0;
        loadingImage.fillAmount = 0;
    }
}
