Gamelogic
  • Home
  • Blog
  • Tools
    • Grids 2 (for Unity)
      • Features
      • Documentation
    • Grids 1 (Legacy, for Unity)
      • 30 games in 30 days
      • Features
      • Tutorials, Documentation, and FAQ
      • Games made with Grids for Unity
      • Examples
      • What is new?
      • Grid Prototypes and Previews
      • Buy
    • Extensions
    • Colors
      • Features
      • Documentation and tutorials
      • Buy
    • Words
      • Features
      • Documentation
      • Buy
    • Abstract Strategy
      • Features
      • Documentation and tutorials
      • Examples
      • Buy
    • Match
      • Features
    • Grids (for GameMaker)
      • 30 games in 30 days
      • Features
      • Documentation
      • Buy
  • Buy
  • Articles
  • Support
    • Knowledge Base
    • Email Support
  • About
    • Meet our team

Displaying an end game message

EndGameMessage680x340To display a message when the game ends you need to add a few lines of code to the game script that you are using, in this example “ShowGameOverMessageGame”. Essentially, you add a event handler to the OnGameOver event that displays a message depending on the configuration.

EndGameMessage

Here is how the code looks:

C#
1
2
3
4
5
6
7
8
9
10
11
12
if (showWinnerID)
{
manager.OnGameOver += OnGameOver;
}
else
{
if (customText == string.Empty)
{
customText = "Game Over!\nPress Space to restart";
}
manager.OnGameOver += () => ShowMessage(customText);
}

The field manager.OnGameOver is an event that fires when the game ends.

The two methods used are these:

C#
1
2
3
4
5
6
7
8
9
10
11
12
private void OnGameOver()
{
var winner = manager.Winners.First();
ShowMessage(
string.Format(
"The winner is {0}. \nPress  to play again.", winner.PlayerID));
}
private void ShowMessage(string message)
{
text.gameObject.SetActive(true);
text.text = message;
}

The rules of this game are the same as the Victory Conditions examples.

To check out this example:

  • Import Abstract Strategy in a new project.
  • Import the package below into the same project.
  • Open the ShowMessageGameOver scene.

ShowMessageGameOver.unitypackage

Share this:

  • Click to share on Facebook (Opens in new window)
  • Click to share on Twitter (Opens in new window)
  • Click to share on LinkedIn (Opens in new window)
  • Click to share on Reddit (Opens in new window)
  • Click to share on Pinterest (Opens in new window)

Related

  1. Using victory conditions  Add a default Victory condition on the GameBoard GameObject. Configure...
  2. Moving a piece and changing turns  Setup a game board with pieces as explained in this...
  3. Creating your own grid game rules  In this tutorial we will focus on implementing Basic Draughts...
  4. Setting up a grid and board  (To Learn more about Grids, see the documentation page for...

  • Setting up a grid and board
  • Moving a piece and changing turns
  • Using victory conditions
  • Animating a piece in the board
  • Home
  • Features
  • Blog
  • About
  • 14 Eglin Road, Sunninghill, Johannesburg, South Africa
  • support@gamelogic.co.za
Stay Connected
  • Facebook
  • Google
  • Linkedin
  • Rss
  • Twitter
  • Gamelogic © 2013