Search Unity

Finding a location on the board.

Discussion in 'Scripting' started by Ants95, Dec 2, 2015.

  1. Ants95

    Ants95

    Joined:
    Oct 19, 2015
    Posts:
    23
    We have a board game which has approximately 300 places (wild guess), we need to know which space the player clicks on. The board is a circle (well a polygon in the shape of a circle)

    Our team has two different ideas and we are not sure which route to take.
    1. We can place 4 game objects (top, left, right, bottom of the board) and when the player clicks on the board game object determine how far from the empty game objects the click was --> which we can then determine the location and calculate the space they intended to click. (hopefully I explained that Ok)

    2. We can put a bunch of empty game objects on each place of the board, and when the player clicks on these invisible game objects we have the id and can use it to determine where they clicked.

    I am not sure which is the better way to go. Is one more efficient than the other? is there a better way to do this.


    TLDR: What is the best way to determine each intersection on the board. We actually need each intersection, not the spaces.
    Selection_012.png
     
    Last edited: Dec 2, 2015
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    Don't use a bunch of empty GameObjects. Use math.

    It's not clear to me how your 300 spaces are arranged or referenced, but you can get the position clicked on the game board in several ways, including a ray cast against a plane, or ScreenToWorldPoint. Then, do the math to figure out which board position (intersection) is closest to the point clicked.
     
    Kiwasi likes this.
  3. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    I would use a single EventSystem object covering the whole board. You can extract the eventData passed in to get the mouse position. Then you write a single algorithm to determine the point.

    This way any clicks on elements in top of your board will not propogate through to the board. I used this strategy in revenge of the ghosts.

    You can put a collider on every single board position. Performance will be fine. But wiring each object up to a central point can be a pain.
     
    JoeStrout likes this.