public void OnMouseClick() { //CREATING THE RAY var ray = _rayProvider.CreateRay(); //SHOTING THE RAY //shooting a raycast to get the tile that the player clicked if (_selector.Check(ray)) { TileField tile; _physicsCache.TryGetTileField(_selector.GetSelection(), out tile); if (_phaseManager.GetCurrentPhase() == Phase.MOVEMENT) { //Two possibilities: the field can or not have a piece if (tile.Piece != null) { // One possibility: If its a piece from the current turn, we try to highlight if (ValidateHighlight(tile.Piece)) { // Three possibilities: // If the clicked tile is the current highlighted, we only dehighlight // If the highlighted tile is null, we only highlight // If the clicked tile isn't the current highlighted, we dehighlight and highlight the clicked one if (tile == m_HighlightedTile) { Deselect(); } else if (m_HighlightedTile == null) { TrySelectEmptyAdjacents(tile); } else if (tile != m_HighlightedTile) { Deselect(); TrySelectEmptyAdjacents(tile); } } } else { //One possibilities: if there is not a piece on the field we clicked, and we already have a highlighted field, we try to move if (m_HighlightedTile != null) { //MOVE PIECE if (tile.IsHighlighting) { //If this tile is highlighted, we can move to this tile. m_HighlightedTile.MovePieceTo(tile); UpdateBoard(tile, m_HighlightedTile); Deselect(); _turnManager.NextTurn(); } } } } else if (_phaseManager.GetCurrentPhase() == Phase.POSITIONING) { //One Possibility: There's no piece on the field, we can only move to an empty space if (tile.Piece == null) { //No piece can be put in the middle on the positioning phase if (tile.Coordinates.x == 2 && tile.Coordinates.y == 2) { return; } if (_turnManager.IsWhiteTurn()) { tile.SetPiece(_pieceProvider.GetNonPlacedWhitePiece()); } else { tile.SetPiece(_pieceProvider.GetNonPlacedBlackPiece()); } _turnIndex++; // Each player places 2 pieces before the next turn if (_turnIndex % 2 == 0) { _turnManager.NextTurn(); } //when all pieces are placed if (_turnIndex == 24) { _phaseManager.StartMovementPhase(); } } } } }