Search Unity

isPointerOverGameObject() not working with touch input

Discussion in 'UGUI & TextMesh Pro' started by Deachprapakorn, Apr 21, 2018.

  1. Deachprapakorn

    Deachprapakorn

    Joined:
    Sep 2, 2015
    Posts:
    3
    Greeting
    I'm having problem with EventSystem.current.isPointerOverGameObject(). I use mouse or touch delta position to control my camera. I want it to avoid if the mouse or finger is on the UI elements. It works perfectly fine with the mouse on pc. But it doesn't work with touch input.

    Here's the code:


    Code (CSharp):
    1. void LateUpdate() {
    2.  
    3. if(Input.touchCount > 0 && Input.GetTouch[0].phase == TouchPhase.Began) {
    4.  
    5. if (!EventSystem.current.IsPointerOverGameObject(Input.GetTouch(0).fingerId)){
    6.  
    7. LocalRotation.x += Input.GetTouch(0).deltaPosition.x * TouchSensitivity;
    8. LocalRotation.y -= Input.GetTouch(0).deltaPosition.y * TouchSensitivity;
    9. LocalRotation.y = Mathf.Clamp(LocalRotation.y, -90f, 90f);
    10.      
    11.    }
    12. }
    13. }
     
  2. Deachprapakorn

    Deachprapakorn

    Joined:
    Sep 2, 2015
    Posts:
    3
  3. surfuay

    surfuay

    Joined:
    Sep 4, 2018
    Posts:
    12
    did you ever find an answer, i have the same problem right now
     
  4. Cascho01

    Cascho01

    Joined:
    Mar 19, 2010
    Posts:
    1,347
    Maybe because there are no MouseOver effects on mobile?
     
  5. Deachprapakorn

    Deachprapakorn

    Joined:
    Sep 2, 2015
    Posts:
    3
    I've never found an answer. If you can get this to work, it would be really great to let me know.
     
  6. yourfriendninjarinplays

    yourfriendninjarinplays

    Joined:
    Sep 18, 2018
    Posts:
    10
    Did Someone Find A Fix To This?
     
  7. zyonneo

    zyonneo

    Joined:
    Apr 13, 2018
    Posts:
    386
    From What I understand....
    Code (CSharp):
    1.  #if UNITY_EDITOR
    2.             if ( !EventSystem.current.IsPointerOverGameObject())
    3.             {
    4.             }
    5.  
    6. #else
    7. if(!EventSystem.current.IsPointerOverGameObject(Input.GetTouch(0).fingerId))
    8. {
    9.  
    10. }
    Try this
     
    Last edited: May 13, 2019