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

public class ClickObject : MonoBehaviour
{

    public GameObject Level;
    public GameObject MonolithInterface;

    void Start()
    {

    }

    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out RaycastHit hit)
                && hit.distance <= 2f)
            {
                var node = hit.transform.parent;
                var nodeHitComponent = node.GetComponent<Hit>();
                if (nodeHitComponent != null)
                {
                    if (nodeHitComponent.ResourceID >= 0
                        || nodeHitComponent.BuildingID >= 0)
                    {
                        node.GetComponent<Hit>().OnHit(Level);
                    }
                    else if (nodeHitComponent.BuildingID == -2)
                    {
                        // monolith
                        MonolithInterface.GetComponent<MonolithInterfaceBehavior>().Show(node.gameObject);
                    }
                }
            }
        }
    }

}
