-1

I have a game with canvas menu on screen with button in it.When user clicks screen,our player jumps.Click on anywhere on screen.

And my button provides player can fire.

So when user touches Button my player jumps and fire.But I just want make it fire not jump.

How can I detect when user clicks button ?

Edit : Thank u guys This Code Solved my Problem ;

if (Input.GetMouseButtonDown(0))
    {
        if (EventSystem.current.IsPointerOverGameObject())
        {
            Debug.Log("Clicked on the UI");
        }
        else
        {
          jump();
        } 
       }
AtakanS.
  • 19
  • 1
  • 1
  • 4

1 Answers1

0

I think it duplicate question but i still answer it :D for fun...

You much detect if clicked UI Object then prevent something .... So we have :EventSystem.IsPointerOverGameObject

And one more thing mobile device will detect touch over gameobject while TouchPhase.Began

https://docs.unity3d.com/ScriptReference/EventSystems.EventSystem.IsPointerOverGameObject.html

Cổ Chí Tâm
  • 330
  • 1
  • 7
  • Thank u man.İt solved my problem I used this code if (Input.GetMouseButtonDown(0)) { if (EventSystem.current.IsPointerOverGameObject()) { Debug.Log("Clicked on the UI"); } else { – AtakanS. Mar 13 '17 at 11:08