private void BuildBoardUI() { boardUI = new ButtonGamePiece[columns, rows]; // instantiating array for buttons for (int x = 0; x < columns; x++) { for (int y = 0; y < rows; y++) { ButtonGamePiece bttn = Instantiate(bttnPrefab, panelGameBoard); bttn.Init(new GridPOS(x, y), () => { ButtonClicked(bttn); }); // anonymous functions have access to all variables in their scope when declared boardUI[x, y] = bttn; } } }
void ButtonClicked(ButtonGamePiece bttn) { ControllerGameClient.singleton.SendPlayPacket(bttn.pos.X, bttn.pos.Y); }