0

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?

1 Answers1

0

You could try putting a sprite behind the UI object when it gets opened so that the tap only applies to the button and the sprite. You could also make the sprite transparent.

SSam202020
  • 71
  • 5