Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

1.4K
Views
Detecting Unity Button Being Held Down And Not Just Pressed

So, I'm trying to make my unity game go from movement using the keyboard to movement using onscreen ui buttons. I used the built in ui buttons in unity, linked the button to the object I'm trying to move, and had it trigger a section of a script to move the object. The problem is it only detects the input of pressing the button at first, how do you detect the button being held down?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

You can check button being held down by check when button is released

First add the Event Trigger component to your button, add two event PointerDown and PointerUp, then set a bool to true on PointerDown, and false on PointerUp, that bool is whether button being held down, e.g:

 public class CheckHeldDown : Monobehaviour
 {
     public bool isHeldDown = false;
 
     public void onPress ()
     {
         isHeldDown = true;
         Debug.Log(isHeldDown);
     }
 
     public void onRelease ()
     {
         isHeldDown = false;
         Debug.Log(isHeldDown);
     }
 }
over 4 years ago · Santiago Trujillo Report

0

If you want to build your game on mobile, you can Detect it with the amount of touches. For example this is some code I just used to make a Nitro button in a racing game:

public class NitroButton : MonoBehaviour
{
    [HideInInspector]
    public bool pushed;

    public void Update()
    {
        if (Input.touchCount >= 2)
        {
            pushed = true;
        }
        else
        {
            pushed = false;
        }
    }
}

This also allows for two finger pushes and such.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!