void Update() { if (Input.GetMouseButtonDown(0)) { startPoint = Input.mousePosition; } else if (Input.GetMouseButtonUp(0)) { if (!dragStarted && !longTapped) { TapDetect(); return; } if (dragStarted) { draggable.OnDragEnded(Input.mousePosition); draggable = null; dragStarted = false; } if (longTapped) { longTapAbleSelected = null; longTapped = false; } } else if (Input.GetMouseButton(0)) { if (dragStarted) { if (Math.Abs(Input.GetAxis("Mouse X")) > 0f || Math.Abs(Input.GetAxis("Mouse Y")) > 0f) { draggable.OnDragMoved(Input.mousePosition); } return; } if (longTapped) { return; } Vector2 diff = startPoint - (Vector2)Input.mousePosition; if (diff.magnitude >= minLengthToStart) { StartDrag(); } else { longTapTimer += Time.deltaTime; if (longTapTimer >= detectionTime) { LongTapDetect(); longTapTimer = 0; } } } }
void StartDrag() { int hits = Physics2D.RaycastNonAlloc(Camera.main.ScreenToWorldPoint(startPoint), Vector2.zero, results, Mathf.Infinity, draggableFilter); if (hits == 0) { return; } Debug.Log($"# Input # StartDrag on {results[hits - 1].transform.gameObject.name}"); draggable = results[hits - 1].transform.gameObject.GetComponent <DragArrowMaker>(); draggable?.OnDragStarted(Input.mousePosition); dragStarted = true; }