Search Unity

Can I stop Inputs with Events?

Discussion in 'UGUI & TextMesh Pro' started by greg_hart, Jan 12, 2018.

  1. greg_hart

    greg_hart

    Joined:
    Nov 26, 2013
    Posts:
    3
    I'm controlling my orbiter camera through Input.GetMouseButton() (for rotate, pan, zoom) and my UI Buttons through Events and the Event Systems. What's the best way to prevent my camera from transforming while I'm dragging on a UI object listening to Events?? I've read that I should be using Events for UI and Input for things like camera manipulation, but let me know if there's a better way. Thanks for any tips!
     
  2. greg_hart

    greg_hart

    Joined:
    Nov 26, 2013
    Posts:
    3
    This nice video helped me find an answer:


    Essentially, transform the camera only if when the mouse/touch began, it wasn't over an EventSystem object.

    Code (csharp):
    1. if ((Input.GetMouseButtonDown(0)) ||
    2.    ((Input.touchCount == 1) && (Input.GetTouch (0).phase == TouchPhase.Began))) {
    3.             if (!EventSystem.current.IsPointerOverGameObject ()) {
    4.                 camXform = true;
    5.             } else {
    6.                 camXform = false;
    7.             }
    8.         }
    9. }
    Let me know if there are better strategies.