GUI Button issue

I have a button in a scene.

Can say ButtonA.

While clicking another button a popup comes.

There is a button in popup also. Say popupbutton.

While clicking on popupbutton, ButtonA works.

How can i escape from this?

15286-button.png

Use GUI.depth to determine which GUI element is on top. This requires the different GUI elements to be in separate scripts.