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

236
Views
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 answers
Answer question

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 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!