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

public class TransformButton : MonoBehaviour
{
    [SerializeField] Transformation transformTo;

    [SerializeField] int tickAmount = 10;

    private Button button;

    private int currentTick = 0;

    private void Init()
    {
        button = GetComponent<Button>();
        button.onClick.AddListener(ButtonClick);
        button.interactable = false;

    }

    private void OnEnable()
    {
        EventManager.Instance.onTick += ButtonActivation;
        if (button == null)
            Init();

        button.interactable = false;
    }

    private void OnDisable()
    {
        EventManager.Instance.onTick -= ButtonActivation;
        currentTick = 0;
    }

    private void ButtonActivation()
    {
        currentTick++;
        if(currentTick >= tickAmount)
        {
            button.interactable = true;
        }
    }

    private void ButtonClick()
    {
        EventManager.Instance.Transformation(transformTo);
    }



}
