Search Unity

Mouse vs Touch detection using onpointerdown

Discussion in 'Scripting' started by r_atio, Sep 25, 2022.

  1. r_atio

    r_atio

    Joined:
    Jul 13, 2022
    Posts:
    3
    i am working on a web game that can be played on both desktops n mobiles, the major difference between these two platforms is the user input... I am using onpointerdown/onpointerup function and the game works perfectly on desktop but when used with touch, it triggers the onpointerdown and onpointerup function multiple times on a single touch which introduces a lot of bugs in the gameplay.
    here, check it out https://diceleweb-866a4.web.app
    Is there a way to solve this issue?
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,697
    Since fingers can't hover, there is no works-in-all-cases conversion between mouse and touch.

    You likely have to change some part(s) of your input logic.

    This is easiest if you have written your game input processing as separate stages:

    - clear all intents (local variables indicating input)
    - read mouse
    - read touch
    - maybe read keyboard
    - maybe read kinect
    - maybe read input off the user's retinal twitching

    When you're all done reading input into intents, then process it.
     
  3. r_atio

    r_atio

    Joined:
    Jul 13, 2022
    Posts:
    3
    Unfortunately i am too noob to understand this...
    is there a way to make 2 different scenes, one using touch API and other events and load that scene based on which platform is detected when the website opens up?
     
  4. DavidTeo

    DavidTeo

    Unity Technologies

    Joined:
    Apr 1, 2021
    Posts:
    69
  5. r_atio

    r_atio

    Joined:
    Jul 13, 2022
    Posts:
    3
    can be done but i was looking for a more generalized way to do this, something that works for both touch and mouse...
    Someone suggested me to use GetMouseButtonDown with raycasthit so ig imma try that