google achievements and leaderboard problem

I have a problem with google achievements and leader board .I have them working but in the leader board the score changes when you exit the game and play again, also the achievements do the same.Here is the code.

public class achActive : MonoBehaviour {

private int score;
private int gamesplayed;

void Awake()
{
    gamesplayed = PlayerPrefs.GetInt("gamesplayed");
    score = PlayerPrefs.GetInt("BestScore");

}
   
void Start()
{
    
      // achievement
  if (score >= 50)
    {
        Social.ReportProgress("Id", 100.0f, (bool success) =>
        {
           
        });
    }

     // achievement
   if (score >= 100)
    {
        Social.ReportProgress("Id", 100.0f, (bool success) =>
        {

        });
    }
      // achievement
     if (score >= 300)
    {
        Social.ReportProgress("Id", 100.0f, (bool success) =>
        {

        });
    }
     // achievement
      if (score >= 500)
    {
        Social.ReportProgress("Id", 100.0f, (bool success) =>
        {

        });
    }
      // achievement
      if (gamesplayed >= 1000)
    {
        Social.ReportProgress("Id", 100.0f, (bool success) =>
        {

        });
    }
     // leaderboard
    Social.ReportScore(score, "Id", (bool success) => {
        // handle success or failure
    });

}

}

Hi,

That’s because you call your different if statements that update the achievements only in the start function :slight_smile:

You should create a function called like UpdateAchievements (), in which you put all the code you wrote in Start () function. Then you call this function within Start () or whenever your want … like at the end of a game.

void Start () {
   UpdateAchievements ();    //That's how to call the function by script
}

public static void UpdateAchievements () { //Public+static so you can call it from anywhere
   // Code you wrote ...
}