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

Detect drag but pass through all other events?

Discussion in 'UGUI & TextMesh Pro' started by johnmoff82, Sep 4, 2014.

  1. johnmoff82

    johnmoff82

    Joined:
    Nov 26, 2013
    Posts:
    2
    I have a screen space GUI that rotates when you drag it. I also have buttons that you can click. I'd like to be able to tap and drag almost anywhere on the screen (including certain buttons) to rotate it, but still be able to tap those buttons and get an onClick. (The buttons should not get a click if the screen is dragged more than a certain threshold.)

    Currently, I have a full-screen transparent Image with a script that implements IDragHandler in front of everything. However, it apparently captures all events, including onClick, so the buttons underneath do not receive those events. Is there a way to ONLY detect IDrag* events and pass through all others? Or is there a better way to accomplish what I'm trying to do?
     
    rakkarage likes this.
  2. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,183
    The 'more correct' way (in terms of how the system is designed) would be to add the drag script to the UI elements you wish to allow the dragging on. You could also write a custom Input module based on the StandaloneInputModule that will pass drag events through. This isn't something we felt would be desirable is most use cases so didn't design the system that way.
     
  3. mweldon

    mweldon

    Joined:
    Apr 19, 2010
    Posts:
    109
    I disagree with every fiber of my being about this not be desired functionality. The ability to add functionality to a UI object without breaking the objects that contain it seems kind of fundamental, IMO.
     
    Gamba04, Clonkex, _slash_ and 3 others like this.
  4. mweldon

    mweldon

    Joined:
    Apr 19, 2010
    Posts:
    109