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

public class ButtonManager : MonoBehaviour
{
    public Button button;

    private void Awake()
    {
        button = GetComponent<Button>();
        Debug.Log(button.tag);
    }

    // Called when object is active
    public void OnEnable()
    {
        // Register event
        PlayerRaycast.OnRaycastHit += ClickButton;
    }

    // Called when object is disabled
    public void OnDisable()
    {
        // Unregister event
        PlayerRaycast.OnRaycastHit -= ClickButton;
    }

    public void ClickButton(RaycastHit hit)
    {
        if (hit.collider.tag.Equals(gameObject.tag))
        {
            button.onClick.Invoke();
        }
    }
}
