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

237
Visualizações
play if the player click in a blank space unity 2d

I'm making a 2d game for mobile and created a pause button on the canvas. the problem is that when i click the pause button the player shoots. I wish there was a way to block the shot when the touch is on an element of the UI. is there any simple way to do this?

this is the code I wrote to detect clicks:

if(Input.touchCount > 0)
        {
            touch_ = Input.GetTouch(0);
            
            if(touch_.phase == TouchPhase.Began)
            {
                touching = true;
                touch_began_fun();
            }
            if(tocando)
            {
                toching_fun();
            }
            if(touch_.phase == TouchPhase.Ended)
            {
                touching = false;
                touch_ended_fun();
            }
        }
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Check the current selected game object of the EventSystem is null. If it is not null, the touch is on a UI element.

if(Input.touchCount > 0)
{
    touch_ = Input.GetTouch(0);

    if(touch_.phase == TouchPhase.Began && EventSystem.current.currentSelectedGameObject == null)
    {
        touching = true;
        touch_began_fun();
    }
    if(tocando)
    {
        toching_fun();
    }
    if(touch_.phase == TouchPhase.Ended)
    {
        touching = false;
        touch_ended_fun();
    }
}
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