1

I am not sure why this is happening, but when a user taps on a UI button on the screen, TapStart.Invoke(); is getting triggered. It should only trigger when the screen is tapped, and the tap isn't on a button.

I assumed that this would stop it: EventSystem.current.currentSelectedGameObject == null but it doesn't seem to be doing so.

void Update() {
  if (Input.touches.Length == 1) {
    Touch touch = Input.GetTouch(0);
    if (touch.phase == TouchPhase.Moved && HasStarted) {
      Swipe.Invoke(StartPosition, touch.position);
      IsSwiping = true;
    }

    if (touch.phase == TouchPhase.Ended) {
      if (!IsSwiping && EventSystem.current.currentSelectedGameObject == null) {
        if (GameManager.Instance.Toast.ResetReady) {
          TapRestart.Invoke();
        } else {
          TapStart.Invoke();
        }
      }
      IsSwiping = false;
      HasStarted = false;
    }
  }
}
Get Off My Lawn
  • 34,175
  • 38
  • 176
  • 338
  • `EventSystem.current.currentSelectedGameObject` is not used for that. `EventSystem.current.IsPointerOverGameObject` is what you are looking for. – Programmer Jun 27 '18 at 15:56
  • @Programmer I have tried using `EventSystem.current.IsPointerOverGameObject` and it is still triggering `TapStart.Invoke()` – Get Off My Lawn Jun 27 '18 at 16:03
  • I suggest you take a look at the duplicate first since there are multiple ways to use that depending on if it is desktop or mobile. If that doesn't work then you have to add EDIT to your question, followed by your new code to show how you're using it otherwise there is no way to know what's the problem. – Programmer Jun 27 '18 at 16:07
  • Okay, the issue is that `EventSystem.current.IsPointerOverGameObject(touch.fingerId)` is returning false when I tap on a button. I think it should be returning true... – Get Off My Lawn Jun 27 '18 at 16:14
  • It looks like it is always false because it is in `TouchPahse.Ended`. If I move it to `TouchPahse.Began` and save the boolean and check in ended it seems to work. – Get Off My Lawn Jun 27 '18 at 16:20
  • Use `IsPointerOverGameObject` without the argument when checking it in `TouchPahse.Ended` – Programmer Jun 27 '18 at 16:49

0 Answers0