diff --git a/Assets/Scripts/DragIndicatorController.cs b/Assets/Scripts/DragIndicatorController.cs new file mode 100644 index 0000000..d96614c --- /dev/null +++ b/Assets/Scripts/DragIndicatorController.cs @@ -0,0 +1,46 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.EventSystems; + +public class DragIndicatorController : MonoBehaviour +{ + private new Camera camera; + private Vector2 startPos, endPos; + + private LineRenderer lr; + + // Start is called before the first frame update + void Start() + { + camera = Camera.main; + lr = gameObject.GetComponent(); + startPos = endPos = Vector2.zero; + lr.positionCount = 2; + lr.material.color = Color.black; + lr.enabled = false; + } + + // Update is called once per frame + void Update() + { + if (!EventSystem.current.IsPointerOverGameObject()) + { + if (Input.GetMouseButtonDown(0)) + { + lr.enabled = true; + startPos = camera.ScreenToWorldPoint(Input.mousePosition); + lr.SetPosition(0, startPos); + } + if (Input.GetMouseButton(0)) + { + endPos = camera.ScreenToWorldPoint(Input.mousePosition); + lr.SetPosition(1, endPos); + } + if (Input.GetMouseButtonUp(0)) + { + lr.enabled = false; + } + } + } +} diff --git a/Assets/Scripts/DragIndicatorController.cs.meta b/Assets/Scripts/DragIndicatorController.cs.meta new file mode 100644 index 0000000..890d774 --- /dev/null +++ b/Assets/Scripts/DragIndicatorController.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 06cd893d9411f8348babf4599964139d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: