Object behind button is clicked too

I have scene where located 4 cubes and button over them, but that button is hidden at start and appears only when some event has happened, but when i click this button, objects that are behind button are also clicked. How can i avoid that? And question refered to previous one - can I somehow make objects that belong to specified layer not interactable, so player can’t click them?

Cube’s clicks are catched by default method in MonoBehaviour -

void OnMouseDown() 
 {
        Debug.Log("Cube clicked");
 }

Clicks on button are handled by method in the Inventor “On Click()” where i choose what to do when button is clicked.

Here’s how my scene looks74774-rsz-2scene.png

You have to check if the the ui system is hitting a element and if then do nothing in your OnMouseDown function.
A code example you can find here:
http://answers.unity3d.com/answers/946052/view.html

@Leopik You can do something like this:

bool cubeWasClicked = false;

void OnMouseDown()
{
  if(cubeWasClicked == false)
  {
      cubeWasClicked = true;
      MakeButtonsAppear();
  }
}

Try putting a canvas group component on your buttons and set to block raycast.