- Home /
Button above Collider is being ignored when clicked.
Hey, I am working on a 2D game. I have a Cell prefab that has a BoxCollider2d
attached. I am listening to the OnMouseDown
event to open a small popup with buttons above that cell.
When I click on the button, the button action is not being performed. However, the cell beneath the button is being triggered, and in return, another small popup gets opened.
I can't disable BoxCollider2d
because I need to close the previously opened popup when I click on another cell.
TL;DR The UI button's action above the BoxCollider2d is being ignored completely.
Check that you have an EventSystem in your scene - that is what makes the buttons work.
Unity automatically inserts it if you create a canvas, but if you copied and pasted the buttons or brought them in from a prefab, you might not have an event system, in which case none of your buttons will work. You can insert an event system: Add object - UI - right at the bottom is Event System.
If you do have an event system, double check that the On Click on your buttons is setup correctly.
If it's not either of those - then there might be a conflict in your code, but from the info you've given, I can't tell.
Your answer
Follow this Question
Related Questions
Use transform.position in FixedUpdate to ensure collision with objects which have Velocity 0 Answers
Polygon Collider 2d doesnt work properly 3 Answers
Collider lets object through 0 Answers
BoxCollider2D have an offset on collision,Collider2D has an collision offset? 0 Answers
Clicking a button will display that buttons text in a seperate text-field 1 Answer