Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

DoSomething when UI Button is held down for x seconds

Discussion in 'Scripting' started by woutervangerven, Jul 20, 2017.

  1. woutervangerven

    woutervangerven

    Joined:
    Oct 4, 2016
    Posts:
    2
    I'm trying to make a system that does something when a UI button is held down for a couple of seconds. After searching through google I couldn't find my answer. So I'm trying it here. I don't have any code that can help you guys understand what i'm doing. But lets say that the button is called "button01". Hopefully someone can help me. :D
     
  2. Flynn_Prime

    Flynn_Prime

    Joined:
    Apr 26, 2017
    Posts:
    387
    Could possibly run a coroutine run when the button is clicked, and have a WaitForSeconds and then an if statement to check if button is still clicked.

    Not entirely sure if this would work though, atleast not with the UI button as I'm pretty sure a 'click' is defined as a click and a release, with events being called on release of the click. Hopefully that made sense
     
  3. GameDevJon

    GameDevJon

    Joined:
    Jul 21, 2017
    Posts:
    25
    You can implement the interface IPointerDownHandler and use this to catch when they "press" the UI element and are holding it down, and use IPointerUpHandler to check when the user has lifted off the UI element.
     
  4. woutervangerven

    woutervangerven

    Joined:
    Oct 4, 2016
    Posts:
    2
    Thanks all for replying on my post.

    I've found my way to do it. I've used the funtion OnPointerDown(Up) and it works perfectly fine :D