Book Image

Unity Game Development Scripting

By : Kyle D'Aoust
Book Image

Unity Game Development Scripting

By: Kyle D'Aoust

Overview of this book

Table of Contents (17 chapters)
Unity Game Development Scripting
About the Author
About the Reviewers

Prototype stats

Now let's figure out which stats we want to keep track of! In this book, the game we create will have a gladiator arena-styled gameplay. So we will have rounds where the player will fight enemies. To win a round, the player will need to kill all of the enemies; to lose a round, the enemies will have to kill the player.

Here's a list of stats that we want to track:

  • Kills

  • Deaths

  • Total gold

  • Current gold

  • Gold spent

  • Level

  • Rounds won

  • Rounds lost

  • Kill-death ratio

  • Win-lose ratio

  • Time played

Assigning the stats to the player

Now that we know what stats we want to track in our game, let's start our script. Create a new C# script and name it StatTracker. Next, let's add our variables to it; these will be the stats that we track:

int pKills = 0;
int pDeaths = 0;
int pTotalGold = 0;
int pCurrentGold = 0;
int pGoldSpent = 0;
int pLevel = 1;
int pRoundsWon = 0;
int pRoundsLost = 0;
float pKDR = 0.00f;
float pWLR = 0.00f;
float pTimePlayed = 0.00f;

As you can see, the variable names are preceded by the...