How to Disable Boxcollider2d when game is paused.

Im Making a hidden objects game on unity 2d, and i used boxcollider2d to traget clicks on objects( for an example i used a star as a hidden object and used a boxcollider2d for whenever i ckick on the star it disapears) and i created a puase menue in canvas with buttons .
the pause menue works but if i pause the game the boxcollider doesnt get disabled .
so if i pause the game and click on the star it still disapears.
Can you please help me ,i want to disable all the boxcolliders when i pause the game.


GetComponent().enabled = false;

You don’t actually need to disable the colliders.

You can check if game is paused in objects’ OnMouseDown() functions instead.

Or you can add a transparent panel with ‘raycast target’ between menu and objects. Objects should be be above it in the hierarchy and menu items should be below.