How to prevent touch to propagate through new UI Button?

Hi All,

I have couple of buttons on the screen and unfortunately when I press one of these buttons the touch propagates through to the screen below which then gets handled by a separate Update() function used to handle touches off the UI buttons.

I’ve tried to utilize the new Eventsystem, but so far with now success. Here’s my code:

private bool WasAButton()
	UnityEngine.EventSystems.EventSystem ct
		= UnityEngine.EventSystems.EventSystem.current;
	if (! ct.IsPointerOverGameObject() ) return false;
	if (! ct.currentSelectedGameObject ) return false;
	if (ct.currentSelectedGameObject.GetComponent<Button>() == null )
		return false;
	return true;

void Update () 
	if (Input.touchCount > 0)
		if (!WasAButton())

DoSomething() gets called even if the touch is on top of a UI button. Buttons work well, but I’d like to make sure that DoSomething() does not get called when pressing a UI button.

… and here is the answer that helped me: