// Update is called once per frame private void Update() { Touch[] touches = Input.touches; for (int touchIndex = 0; touchIndex < touches.Length; touchIndex++) { if (touches[touchIndex].phase == TouchPhase.Ended) { Vector3 worldPoint = Camera.main.ScreenToWorldPoint(touches[touchIndex].position); Vector2 touchPosition = new Vector2(worldPoint.x, worldPoint.y); if (_collider2D.OverlapPoint(touchPosition)) { _inputTrigger.TriggerInput(ActionType.DragAndDrop); return; } } } }
// Update is called once per frame private void Update() { if (Input.touchCount > 0) { if (Time.time < _lastTap + _tapThreshold) { return; } Touch touch = Input.GetTouch(0); if (touch.phase == TouchPhase.Ended) { Vector3 worldPoint = Camera.main.ScreenToWorldPoint(touch.position); Vector2 touchPosition = new Vector2(worldPoint.x, worldPoint.y); if (_collider2D.OverlapPoint(touchPosition)) { _lastTap = Time.time; _inputTrigger.TriggerInput(ActionType.Tap); } } } }
// Update is called once per frame private void Update() { Touch[] touches = Input.touches; for (int touchIndex = 0; touchIndex < touches.Length; touchIndex++) { Vector3 touchWorldPoint = Camera.main.ScreenToWorldPoint(touches[touchIndex].position); //if (log) log.text = "\n col.bounds " + col.bounds+ "\n touches[touchIndex].position " + touches[touchIndex].position + "\n touchWorldPoint " + touchWorldPoint; if (_collider.OverlapPoint(touchWorldPoint)) { if ((swipeDrag && touches[touchIndex].phase == TouchPhase.Moved) || (!swipeDrag && touches[touchIndex].phase == TouchPhase.Ended)) { distanceSwiped += touches[touchIndex].deltaPosition.magnitude; if (distanceSwiped > minDistanceForSwipe) { leftToRightSwiped = touches[touchIndex].deltaPosition.x > 0; if (leftToRightSwiped != _lastSwipe.LeftToRight) { _lastSwipe = new Swipe(distanceSwiped, Time.time - sinceLastSwipe, leftToRightSwiped); SaveSwipe(_lastSwipe); _theSwipeIsRight = IsThisSwipeRight(); string animationToPlay = _theSwipeIsRight ? "Getting_Scratched" : "Angry_Idle"; Monster.Instance.AnimationHelper.UpdateAnimation(animationToPlay, 1f); touch = touches[touchIndex]; distanceSwiped = 0; if (log) { log.text = "\n Swiped! \n" + GetDebugInfo(touch); } swipeCount++; if (swipeCount == swipesRequiredForTrigger && _theSwipeIsRight) { _inputTrigger.TriggerInput(ActionType.Swipe); } } sinceLastSwipe = Time.time; } } } } if (sinceLastSwipe + maxDelayBetweenSwipes < Time.time) { distanceSwiped = 0; swipeCount = 0; if (log) { log.text = "\n Reset! \n" + GetDebugInfo(touch); } // Clear the previous swipes. _previousSwipes.Clear(); } }