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. Dismiss Notice

Detect touch events only when NOT touching UI elements

Discussion in 'iOS and tvOS' started by eco_bach, Jul 19, 2017.

  1. eco_bach

    eco_bach

    Joined:
    Jul 8, 2013
    Posts:
    1,601
    Hi
    Am using the following code to detect touch events only when NOT over any UI element. However, it is not working, touch events still propagate.
    Can any iOS experts help?
    Code (csharp):
    1.  
    2. var touch = Input.GetTouch(0);
    3.                 if (touch.phase == TouchPhase.Began && !EventSystem.current.IsPointerOverGameObject())
     
  2. DigitalDennis

    DigitalDennis

    Joined:
    Jul 24, 2017
    Posts:
    2
    nems808 likes this.
  3. SoliderSpy

    SoliderSpy

    Joined:
    Nov 30, 2016
    Posts:
    3
    Hahaha yes we are all watching the same ARkit Unity Zombie tutorial! xD lolololol
     
  4. BogdanLysogora

    BogdanLysogora

    Joined:
    Nov 12, 2014
    Posts:
    2
    Sometimes, it is necessary to include additional TouchPhase conditions, e.g.
    Code (csharp):
    1. Input.GetTouch(0).phase == TouchPhase.Began || Input.GetTouch(0).phase == TouchPhase.Stationary
     
  5. araz01

    araz01

    Joined:
    Aug 2, 2016
    Posts:
    53