Search Unity

How to check if a Tap is on a UI image?

Discussion in 'Input System' started by roseportalgames, Sep 8, 2021.

  1. roseportalgames

    roseportalgames

    Joined:
    Aug 9, 2017
    Posts:
    173
    With the old Input system, I would just use a Button with OnClick or an Event Trigger with PointerClick.

    I am now using the new Input system and I turned on Touch input simulation because I'm making an Android app.

    The problem is now, that when I play in the editor and use a Button with OnClick or Event Trigger with PointerClick, the event is registered twice. Once by the mouse and once by the Touch input simulation.

    So I want to create a system that only checks using Tap. I created a Touch tap event (see screenshot).
    But then how do I actually check if this Tap is on the button that I created?

    My buttons are on an Overlay camera.

    upload_2021-9-8_21-43-1.png

    Should I write an InputManager script that checks for FirstTouchTap and then uses a Raycast to check which UI image it is over?
    But then how do I link that to trigger the script function that I want? Because it used to be very simple to use Button and OnClick and then a reference to the script and function I want to call. But not sure how I would do that setup if I just have one InputManager script that deals with all taps.