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

public class SelectArea : MonoBehaviour
{
    public GameObject sd;
    public Canvas canvas;

    Vector3 startPos, endPos;
    GameObject tempDrag;

    void Start()
    {
    }

    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            startPos = new Vector3(Input.mousePosition.x, Input.mousePosition.y, 0);
            tempDrag = Instantiate(sd, startPos, Quaternion.identity) as GameObject;
            tempDrag.transform.parent = canvas.transform;
        }

        if (Input.GetMouseButton(0))
        {
            endPos = new Vector3(Input.mousePosition.x, Input.mousePosition.y, 0);

            tempDrag.transform.localScale = new Vector3(endPos.x - startPos.x, endPos.y - startPos.y, 0);
        }

        if (Input.GetMouseButtonUp(0))
        {
            Destroy(tempDrag);
        }
    }
}
