Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

IsPointerOverGameObject fro touchscreen

Discussion in 'Editor & General Support' started by KrisBendix, Jun 27, 2015.

  1. KrisBendix

    KrisBendix

    Joined:
    May 26, 2015
    Posts:
    15
    Hi.
    I'm sure I am not the first one to have this problem.
    I had a bug where I was shooting the thing when I pressed on UI. Fixed it with:

    Code (CSharp):
    1. if (Input.GetMouseButtonDown(0))
    2.         {
    3.             EventSystem eventSystem = EventSystem.current;
    4.             if (eventSystem.IsPointerOverGameObject())
    5.             {
    6.                 return;
    7.             }
    8.             else if //rest of code with raycast etc
    9.  
    Now it works for mouse based version (PC, Web...) perfectly. But it obviously doesn't work for touchscreens.
    So is there any way to make IsPointerOverGameObject work for mobile?
    One idea is to tell it where "pointer" is based on where screen is touched and after that do eventSystem.IsPointerOverGameObject()... but how to do that if it is possible?
     
  2. KrisBendix

    KrisBendix

    Joined:
    May 26, 2015
    Posts:
    15
    Fixed the problem by un-checking Touch Input Module (Script) in Event System and checked Allow Activation On Mobile Device under Standalone Input Module (Script). Now (eventSystem.IsPointerOverGameObject()) works for touchscreens. At least on my Android. Haven't found any problems yet. And how could there be(?), game is only about taping on screen and doing only one raycast per tap.

    But it may not work for everyone. Multi-touch may not work etc.
     
  3. paulfanmedia

    paulfanmedia

    Joined:
    Jun 5, 2015
    Posts:
    1
  4. rocamalo

    rocamalo

    Joined:
    Jun 29, 2021
    Posts:
    2
    Hello, how do you unckec the Touch Input module?