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

public class ProjectorManager : MonoBehaviour {

    public static ProjectorManager instance;

    private Projector proj;

    public void Awake()
    {
        if (instance == null)
        {
            instance = this;
        }
        else if (instance != this)
        {
            Destroy(gameObject);
        }

        proj = instance.GetComponent<Projector>();
    }

    public void MoveProjector(Vector3 pos)
    {
        pos.y = 10;
        transform.position = pos;
    }

    public void Update()
    {
        Vector2 mousePos = Input.mousePosition;
        RaycastHit hit;
        if (Physics.Raycast(Camera.main.ScreenPointToRay(mousePos), out hit, 100f, LayerMask.GetMask("Hover")))
        {
            proj.enabled = true;
            MoveProjector(hit.collider.gameObject.transform.position);
        }
        else
        {
            proj.enabled = false;
        }
    }
}
