Search Unity

  1. Get the latest news, tutorials and offers directly to your inbox with our newsletters. Sign up now.
    Dismiss Notice

Help Wanted How to Input.GetMouseButtonDown(0) with new InputSystem

Discussion in 'Scripting' started by Ascanio1980, Apr 22, 2021.

  1. Ascanio1980


    Jun 7, 2019

    What I am trying to do:
    • A non-gaming app that allows interaction through remote control as well as touchscreen;
    • The UI adapts for remote control (focus rectangle), for touchscreen (all interactable hot areas become evident), or no interaction (visual elements on screen are minimized);
    • As the user performs an action on the remote control, the UI responds and switches to REMOTE mode;
    • As the user approaches the screen, a proximity sensor triggers TOUCH mode;
    • As the user touches the screen, as a fallback in case the sensor didn't work, UI switches to TOUCH mode;
    • After a timeout from last interaction, the UI switches to NONE mode;

    Basically what I need to do is listen to mouse / touch input, regardless of where it takes place (I don't care what is being touched, I just need that to generically trigger the switch to TOUCH mode and restart the timeout counter to switch back to NONE mode.

    With the old system I could achieve this like so:

    Code (CSharp):
    1. private void Update()
    2. {
    3.     If(Input.GetMouseButtonUp(0) || Input.touchCount > 0)
    4.     {
    5.         SetInteractionModeTouch();
    6.         StartTimeoutToModeNone();
    7.     }
    8. }
    Of course this is triggering an exception with the new InputSystem.
    I am trying to sift through the documentation, but every time I do, I get more confused.
    Do you have a clean way to do this, ideally by listening to an event directly (avoiding using the Update function)?
  2. PraetorBlue


    Dec 13, 2012
  3. Ascanio1980


    Jun 7, 2019
    Hi PraetorBlue,

    could you give me a hint about how to go about this (just in code, without having to set up things in the editor / project)?

    Other question, will canceled do the following:
    - be invoked for any and all touch / mouse input, regardless of whether it is hitting an object that "captures it" or not?
    - not be invoked for any keyboard input (my remote control is a CAN-bus device interfaced via a USB HID device that emulates a Keyboard

    Thank you!!!