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

public class ShapeDragging : MonoBehaviour {
	
	public static ShapeDragging DraggedShape = null; 

	public ShapesEnum Shape;
	private bool isDragged;
	private Vector3 dragDelta;

	private Vector3 startPosition;

	void Start()
	{
		isDragged = false;
		startPosition = transform.position;
	}

	// Update is called once per frame
	void Update () {
		if(GameManager.GameOver) return;
		/*if(Input.GetMouseButtonDown(0))
		{
			Camera.main.ScreenToWorldPoint(Input.mousePresent)
		}*/	
		if(isDragged)
		{
			transform.position = Camera.main.ScreenToWorldPoint(Input.mousePosition) + dragDelta;
		}
	}

	void OnMouseDown()
	{
		if(GameManager.GameOver) return;

		isDragged = true;
		dragDelta = transform.position - Camera.main.ScreenToWorldPoint(Input.mousePosition);
		DraggedShape = this;
	}

	void OnMouseUp()
	{
		StartCoroutine(JumpBack());
	}

	IEnumerator JumpBack()
	{
		yield return null;
		isDragged = false;
		this.transform.position = startPosition;
		DraggedShape = null;
	}



}
