xXElsterXx
xXElsterXx

Reputation: 39

Swipe cause GetMouseButtonDown(0)

I have a script that recognizes swiping input. When I now start a swipe, it also triggers Input.GetMouseButtonDown(0). Can you tell me how to delete Input.GetMouseButtonDown(0) that comes from the swipe?

With that swipe the game gets paused. (with Time.timeScale = 0f;) After resume, the action which was triggered from Input.GetMouseButtonDown(0) before pausing the game goes on.

My Ideas: Work with TouchPhase.Stationary or look for short tap?

Upvotes: 0

Views: 190

Answers (2)

Paweł Łęgowski
Paweł Łęgowski

Reputation: 830

I would recommend not using Input class at all, it causes many problems, better have separate RaycastTarget on UI with Script implementing IPointerDownHandler, IPointerUpHandler, that will ensure only one RaycastTarget at the moment is handling your touches. Input.GetMouseButton will return true even if some RaycastTarget already should have consumed your events.

Upvotes: 0

Ron
Ron

Reputation: 1866

Off the top of my head, you can either:

  1. Call Input.ResetInputAxes; it will clear all input flags for one frame.
  2. Set a flag that a swipe was handled, and check for it when checking for Input.GetMouseButtonDown(0) elsewhere.

Both will require ensuring that the swipe detection happens before you check for Input.GetMouseButtonDown(0).

One way of ensuring it, is by using Unity's script execution order settings.

Upvotes: 1

Related Questions