Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

1.4K
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda