Skip to main content
2 of 3
Added an additional option.
JKreft
  • 113
  • 4

Best Practices for Locating Clicks

I am building a 2D board game in Unity with a static camera pointed down at the game board. During the active phase of each player's turn, I want to detect where they click on the board. Fortunately, the board is laid out in an easy rectangular grid. (Essentially a trio of 5x5 grids).

Which of the following would be best practice to implement this?

  1. Create invisible colliders for every square on the board and create a translation function that translates those back to board positions (5,3) with Raytracing?

  2. Get the translated coordinates of the click and use a function to figure out which square (if any) the click is in using the mouseclick event handler (by calculating which square the grid coordinates fall in)?

  3. Make each square a button with its grid identity encoded and use that in its "OnPressed" function?

Edit: 4) Some other idea I haven't thought of yet?

Experience level: I'm just learning unity, but have written a lot of C# (and tons of other code).

JKreft
  • 113
  • 4