Achievement trackers

In this part of the chapter, we will add trackers for each of our achievements. Each tracker will have its own function. The functions will be very similar to each other, but will have their own variables to affect.

When the functions are called, it'll take in an integer; this integer is the amount of the stat that we want to check. Within the function, we check with our bool variables to see whether that achievement can still be gained. Next, we check the amount in order to iterate the achievement level appropriately.

Once the achievement level is at its highest amount, we disable the ability to gain more achievements for that skill.

Tracking the kills

Our first tracker will track the player kills; let's add the tracker function now:

void Kills(int Amount)
{
  if(getKills)
  {
    if(Amount >= 10 && Amount < 49)
    {
      if(achKills != 1)
        achKills++;
    }
    if(Amount >= 50 && Amount < 99)
    {
      if(achKills != 2)
        achKills++;
    }
    if(Amount >= 100 && Amount < 249)
    {
      if(achKills != 3)
        achKills++;
    }
    if(Amount >= 250 && Amount < 499)
    {
      if(achKills != 4)
        achKills++;
    }
    if(Amount >= 500 && Amount < 999)
    {
      if(achKills != 5)
        achKills++;
    }
    if(Amount >= 1000)
    {
      if(achKills != 6)
        achKills = 6;
    }
    if(achKills == 6)
      getKills = false;
  }
}

Tracking the gold total

The next tracker will track how much gold the player gained in the entire time they played the game. Add this function to the script:

void TotalGold(int Amount)
{
  if(getTotGold)
  {
    if(Amount >= 100 && Amount < 249)
    {
      if(achTotGold != 1)
        achTotGold++;
    }
    if(Amount >= 250 && Amount < 499)
    {
      if(achTotGold != 2)
        achTotGold++;
    }
    if(Amount >= 500 && Amount < 999)
    {
      if(achTotGold != 3)
        achTotGold++;
    }
    if(Amount >= 1000 && Amount < 4999)
    {
      if(achTotGold != 4)
        achTotGold++;
    }
    if(Amount >= 5000 && Amount < 9999)
    {
      if(achTotGold != 5)
        achTotGold++;
    }
    if(Amount >= 10000)
    {
      if(achTotGold != 6)
        achTotGold = 6;
    }
      
    if(achTotGold == 6)
      getTotGold = false;
  }
}

Tracking the gold spent

This tracker will track how much gold the player spent on items during the time they played the game:

void GoldSpent(int Amount)
{
  if(getGoldSpnt)
  {
    if(Amount >= 100 && Amount < 249)
    {
      if(achGoldSpnt != 1)
        achGoldSpnt++;
    }
    if(Amount >= 250 && Amount < 499)
    {
      if(achGoldSpnt != 2)
        achGoldSpnt++;
    }
    if(Amount >= 500 && Amount < 999)
    {
      if(achGoldSpnt != 3)
        achGoldSpnt++;
    }
    if(Amount >= 1000 && Amount < 4999)
    {
      if(achGoldSpnt != 4)
        achGoldSpnt++;
    }
    if(Amount >= 5000 && Amount < 9999)
    {
      if(achGoldSpnt != 5)
        achGoldSpnt++;
    }
    if(Amount >= 10000)
    {
      if(achGoldSpnt != 6)
        achGoldSpnt = 6;
    }
      
    if(achGoldSpnt == 6)
      getGoldSpnt = false;
  }
}

Tracking the player's level

This will track the player's level in the game. A player can increase their level in any way you wish within the game:

void Level(int Amount)
{
  if(getLvl)
  {
    if(Amount >= 5 && Amount < 9)
    {
      if(achLvl != 1)
        achLvl++;
    }
    if(Amount >= 10 && Amount < 24)
    {
      if(achLvl != 2)
        achLvl++;
    }
    if(Amount >= 25 && Amount < 49)
    {
      if(achLvl != 3)
        achLvl++;
    }
    if(Amount >= 50 && Amount < 74)
    {
      if(achLvl != 4)
        achLvl++;
    }
    if(Amount >= 75 && Amount < 99)
    {
      if(achLvl != 5)
        achLvl++;
    }
    if(Amount >= 100)
    {
      if(achLvl != 6)
        achLvl = 6;
    }
      
    if(achLvl == 6)
      getLvl = false;
  }
}

Tracking the rounds won

This will track how many rounds the player has won overall:

void RoundsWon(int Amount)
{
  if(getRndsW)
  {
    if(Amount >= 5 && Amount < 9)
    {
      if(achRndsW != 1)
        achRndsW++;
    }
    if(Amount >= 10 && Amount < 24)
    {
      if(achRndsW != 2)
        achRndsW++;
    }
    if(Amount >= 25 && Amount < 49)
    {
      if(achRndsW != 3)
        achRndsW++;
    }
    if(Amount >= 50 && Amount < 74)
    {
      if(achRndsW != 4)
        achRndsW++;
    }
    if(Amount >= 75 && Amount < 99)
    {
      if(achRndsW != 5)
        achRndsW++;
    }
    if(Amount >= 100)
    {
      if(achRndsW != 6)
        achRndsW = 6;
    }
      
    if(achRndsW == 6)
      getRndsW = false;
  }
}

Tracking the time played

This tracker will track how long the player played the game. Unity tracks time in seconds; we will track the time stat in minutes, so we will be dividing the time by 60:

void TimePlayed(float Amount)
{
  if(getTime)
  {
    float minutes = Amount / 60.00f;

    if(minutes >= 10.00f && minutes < 59.00f)
    {
      if(achTime != 1)
        achTime++;
    }
    if(minutes >= 60.00f && minutes < 119.00f)
    {
      if(achTime != 2)
        achTime++;
    }
    if(minutes >= 120.00f && minutes < 179.00f)
    {
      if(achTime != 3)
        achTime++;
    }
    if(minutes >= 180.00f && minutes < 239.00f)
    {
      if(achTime != 4)
        achTime++;
    }
    if(minutes >= 240.00f && minutes < 299.00f)
    {
      if(achTime != 5)
        achTime++;
    }
    if(minutes >= 300.00f)
    {
      if(achTime != 6)
        achTime = 6;
    }
      
    if(achTime == 6)
      getTime = false;
  }
 }
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.143.247.53