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

public class darg2 : MonoBehaviour
{
    private float startPosX;
    private float startPosY;
    public bool isBeingHeld = false;
    public bool isGround;
    public bool isSupport;
    public bool affectedBySupport;
    public GameObject affetctedSupportSnap;
    public GameObject placeHolder;

    public Vector2 startPos;

    public string objectName;

    // Start is called before the first frame update
    void Start()
    {
        startPos = transform.position;
    }

    // Update is called once per frame
    void Update()
    {


        if (isBeingHeld == true)
        {
            Vector3 mousePos;
            mousePos = Input.mousePosition;
            mousePos = Camera.main.ScreenToWorldPoint(mousePos);

            this.gameObject.transform.localPosition = new Vector3(mousePos.x - startPosX, mousePos.y - startPosY, 0);
        }

    }

    private void OnMouseDown()
    {

        Vector3 mousePos;
        mousePos = Input.mousePosition;
        mousePos = Camera.main.ScreenToWorldPoint(mousePos);

        startPosX = mousePos.x - this.transform.localPosition.x;
        startPosY = mousePos.y - this.transform.localPosition.y;

        isBeingHeld = true;
    }

    private void OnMouseUp()
    {
        isBeingHeld = false;
    }

    private void OnTriggerStay2D(Collider2D col)
    {




        //if (isBeingHeld == false)
        //{

        //    transform.position = col.transform.position;
        //    transform.SetParent(col.transform);


        //}
        //else
        //{
        //    transform.position = startPos;
        //}

        if (col.tag == "Change")
        {
            GetComponent<PolygonCollider2D>().enabled = true;

        }
        else
        {
            GetComponent<PolygonCollider2D>().enabled = false;
        }
    }
}
