Using Victory Conditions
Make sure you have configured the line directions on the Grid Game Rules component as explained in the Capturing an Enemy Piece tutorial.
- Add a victory condition to the GameBoard game object. In this example, we will add the
Pieces in a Rowvictory condition. - Configure the victory condition in the inspector.
- Set Victory Kind to
Victory. This means when the condition is met, the player who achieves it wins. - Set Victory Check Periods to
PlayerChange. - Set Number of pieces to
3. - Since all the pieces are the same, we can leave out the ID.
- Set Victory Kind to
- Add an
Other Players Conditionto the GameBoard GameObject. This condition will make the other player lose when the first player wins.
In general, more than one victory condition can be added.
You can add a handler to the OnGameOver event on the Game Manager to execute code. Note that it will only be called when all the players have victory states assigned. To know who won or lost, look at the Winners and Losers property in the Game Manager. You can see how to do this in Displaying an End Game Message.
public void Start()
{
InitializeGameManager();
InitializePlayers();
ResetGame();
manager.OnGameOver += OnGameOver;
}
