I am making a Tower Defence game for mobile and I'm struggling to fix this bug for the last couple of weeks. In order to build a tower, I tap on a tile, which pops up a UI menu with a couple of towers to choose from. If behind the location I tap on the UI to choose the tower there is another valid position to build a tower, the tap goes through the UI and selects the new valid tile.
I have an empty game object, which nests a canvas, which nests the buttons.
I have tried using the following possible fixes, but didn't work in my case:
- Graphic raycaster on the canvas
if (EventSystem.current.IsPointerOverGameObject())
return;
if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began)
if (EventSystem.current.IsPointerOverGameObject(Input.GetTouch(0).fingerId))
return;
How should I proceed?