Not able to click on objects

Hey everyone, I was wondering if anyone could help me with this. I have been trying to figure it out for days. I would really appreciate the help. I am trying to figure out how to null/not have click activated when I click on the pop up UIs. The pictures as shown:

alt text

I have a script in which I am able to click on the triangles. The blue space is nulled out/does not do anything. The code I am using is:

public class ClickObject : MonoBehaviour {
[SerializeField]
private GameObject NextLevelUI;
[SerializeField]
private GameObject TryAgainUI;


	void  Update (){


	
		RaycastHit2D hit;




		if(Input.GetMouseButtonDown(0)){

		
			hit=Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition) , Vector2.zero);
			if (hit.collider != null){
				TryAgainUI.SetActive(true);
				if(hit.collider.GetComponent<MoveSample>()!= null && hit.transform.gameObject.tag=="TriangleP"){
					NextLevelUI.SetActive(true);
					TryAgainUI.SetActive (false);{
						Debug.Log("SUCCESS");

When I click on the right object that has the movesample script attached, It directs to the correct pop up UI. When I clicked on the wrong object, it goes to the incorrect pop up. Here is an example of the correct UI:

alt text

What I want to do is have the ability to ONLY click on the button and nothing else. The triangles and background all null/unable to do anything. I have been looking into bools, event systems, if else statements, but not sure how to do this. If anyone could help I would GREATLY appreciate it. Thank you.

I’m gussing you need to do this:

void  Update ()
{
	if (!EventSystem.current.IsPointerOverGameObject()){
		//put your code here...
	}
}

Pay attention to the ! before the condition which reverses it.

This is not the recommended way though and if you wanna see a better way, check this tutorial on 1

Update:
if (!EventSystem.current.IsPointerOverGameObject()) means if the mouse pointer is not already over a UI element. So, there must be a UI element such as Panel or Image overlapping your scene objects (your triangles) to block the click event. Do you have any? If not (which is what I’m assuming), you can make an invisible background for your UI button which should fill the whole screen and its job is to block click events from going to your Triangles. You need to activate this background whenever you activate the button, and of course deactivate it whenever you deactivate your button UI. This invisible background must be drawn after your button, or in other words, it must be above the button in the hierarchy pane.

To make an invisible background, create a Panel UI and set its Image component to invisible like the following picture:

69533-screen-shot-2016-05-06-at-85055-pm.png