Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by tonyjoseph456 · Mar 19, 2015 at 11:46 AM · uieventsystemunity 4.6

EventSystem.current.IsPointerOverGameObject getting clicked through UI buttons in android devices in Unity 4.6.3p1

In my game, there are 2 UI Panels with 4 buttons on the screen. One panel is at the bottom, and the other panel is at the left side of the screen. The bottom panel is always visible through out the game, and the left panel pops out on clicking each of the four the UI buttons on the bottom panel. Beneath the UI there is my game scene containing the bg and other game objects. For showing the UI I have used one seperate camera and for showing the main game scene, I have used the main camera. Now coming to the problem, I need to detect the clicks on the bg of my game. So the problem is that, when I click on the UI buttons, the UI button is also getting clicked and the bg is also getting clicked through the UI button. I want only the UI button to get clicked when I click on them, and disable the click on the bg of my game.

So for this purpose, I have used the EventSystem.current.IsPointerOverGameObject in my code. It is working fine on the Unity Editor, but when I tested it on Android Device, it is not giving the results, which I expected, that is bg is getting clicked through the UI button click. I tried several codes and methods which I have seen in the stackoverflow, Unity Answers and Unity Forums, but none of them are working for me in Android Devices but every thing is working fine on Unity Editor.

My game is a 2d game and I'm using the Unity 4.6.3p1 version. I have attached a script called Tween.cs to the bg game object. Also I have attached a box collider 2D for detecting OnMouseDown. In the attached script, I have used the OnMouseDown() method. This is the code which I have used in my game.

 void OnMouseDown()
 {
 if(Input.GetMouseButtonDown(0))
 {
     foreach (Touch touch in Input.touches)
     {
         int pointerID = touch.fingerId;
         //Debug.Log ("Pointer ID "+pointerID);
         if (EventSystem.current.IsPointerOverGameObject(pointerID))
         {
             // at least on touch is over a canvas UI
             Debug.Log ("Clicked on UI");
             return;
         }
         else
         {
             Debug.Log("Clicked on BG");
             if(this.gameObject.name=="Kitchen")
             {
                 Debug.Log ("Tapped on BG Kitchen");
             }
         }
             
     }
 }
 }

This is one example which I got from http://gamedev.stackexchange.com/.

Now another code:

 void OnMouseDown()
 {
     if (Input.touchCount > 0 && Input.GetTouch (0).phase == TouchPhase.Began) 
     {
         if (IsPointerOverGameObject (Input.GetTouch (0).fingerId)) 
         {
             Debug.Log("Hit UI button, Ignore Touch");
         } 
         else 
         {
              Debug.Log("Clicked on BG");
             if(this.gameObject.name=="Kitchen")
             {
                 Debug.Log ("Tapped on Kitchen");
             }
         }
     }        
     }
 bool IsPointerOverGameObject( int fingerId )
 {
     Debug.Log ("Finger ID"+fingerId);
     EventSystem eventSystem = EventSystem.current;
     return ( eventSystem.IsPointerOverGameObject( fingerId ) && eventSystem.currentSelectedGameObject.tag);
 }

Can someone please help me to solve this problem. Is there some thing that I did wrong in this code. Thanks in advance.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by fabian-mkv · Dec 21, 2015 at 04:35 PM

I had similar question and found a solution:

http://answers.unity3d.com/questions/1115464/ispointerovergameobject-not-working-with-touch-inp.html#answer-1115473

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Why can't I reference Graphics Raycaster in my gameObject? 1 Answer

New UI rotating speedometer? 0 Answers

Trigger UI element callback from script 0 Answers

How to start the game with CurrentInputMode being "Buttons" instead of "Mouse" in StandaloneInputModule? 0 Answers

Unity UI: How to stop select event from propagating? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges