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

public class HintBlock  : MonoBehaviour{

    IPoint mapSize;
    float consoleLeftBorad;

     void Start(){
         this.mapSize = Laboratory.mapSize;
         consoleLeftBorad = -(Screen.width * 0.5f - 500);
     }

     void Update()
     {        
         move(IPoint.createMapIPointByWordVector(getMouseVector(), mapSize));
     }

    public void move(IPoint coor)
    {
        transform.localPosition = coor.mapIPoint2WordVector(mapSize);
    }

    Vector3 getMouseVector()
    {
        Camera gameCamera = Camera.main;
        Ray ray = gameCamera.ScreenPointToRay(Input.mousePosition);
        RaycastHit hit;
        if (Physics.Raycast(ray, out hit))
        {
            if (EventSystem.current.IsPointerOverGameObject())
            {
                Vector3 mousePoint = Input.mousePosition - Bag.decVector;

                if (mousePoint.x < consoleLeftBorad && mousePoint.y > -330)
                {
                    //Debug.Log(mousePoint);
                }
                else
                {
                    return new Vector3(9999, 9999, 0);
                }
            }

            if (hit.transform.name == "Click Plane")
            {
                return hit.point;
            }
        }

        return new Vector3(0, 999, 0);
    }
}
