Assets/Scripts/Custom/Score.cs
/// <summary>
/// Method that compares the score with the saved scores of the leaderboard. 
/// If the user reached a score high enough for the leaderboard. 
/// He will be added and the rest of the scores will be moved down.
/// </summary>
/// <param name="score">The score the user made</param>
Method that compares the score with the saved scores of the leaderboard.
If the user reached a score high enough for the leaderboard.
He will be added and the rest of the scores will be moved down.
Method that compares the score with the saved scores of the leaderboard . If the user reached a score high enough for the leaderboard . He will be added and the rest of the scores will be moved down .
public void AddScoreToLeaderboard(int score)
    {
        bool added = false;
        int point = 0;
        string username = "";
        foreach (string lbPoint in leaderBoardPoints)
        {
            string[] playerName = lbPoint.Split(' ');
            if (added)
            {
                int tempPoint = PlayerPrefs.GetInt(lbPoint);
                string tempUsername = PlayerPrefs.GetString(playerName[0] + " " + playerName[1]);
                PlayerPrefs.SetInt(lbPoint, point);
                PlayerPrefs.SetString(playerName[0] + " " + playerName[1], username);
                point = tempPoint;
                username = tempUsername;
                continue;
            }
            point = PlayerPrefs.GetInt(lbPoint);
            if (score != 0 && score > point && !added)
            {
                PlayerPrefs.SetInt(lbPoint, score);
                arrayListValueOfHighscore = playerName[0] + " " + playerName[1];
                username = PlayerPrefs.GetString(playerName[0] + " " + playerName[1]);
                added = true;
                submitUsernameButton.gameObject.SetActive(true);
                usernameInputField.gameObject.SetActive(true);
            }
        }
        if (!added)
        {
            GetComponent<EndScreen>().SetBackButtonActive();
        }
    }
public void AddScoreToLeaderboard ( int score ) { bool added = false ; int point = 0 ; string username = " " ; foreach ( string lbPoint in leaderBoardPoints ) { string [ ] playerName = lbPoint . Split ( ' ' ) ; if ( added ) { int tempPoint = PlayerPrefs . GetInt ( lbPoint ) ; string tempUsername = PlayerPrefs . GetString ( playerName [ 0 ] + " " + playerName [ 1 ] ) ; PlayerPrefs . SetInt ( lbPoint , point ) ; PlayerPrefs . SetString ( playerName [ 0 ] + " " + playerName [ 1 ] , username ) ; point = tempPoint ; username = tempUsername ; continue ; } point = PlayerPrefs . GetInt ( lbPoint ) ; if ( score != 0 && score > point && ! added ) { PlayerPrefs . SetInt ( lbPoint , score ) ; arrayListValueOfHighscore = playerName [ 0 ] + " " + playerName [ 1 ] ; username = PlayerPrefs . GetString ( playerName [ 0 ] + " " + playerName [ 1 ] ) ; added = true ; submitUsernameButton . gameObject . SetActive ( true ) ; usernameInputField . gameObject . SetActive ( true ) ; } } if ( ! added ) { GetComponent < EndScreen > ( ) . SetBackButtonActive ( ) ; } }
Method that compares the score with the saved scores of the leaderboard.
Method that compares the score with the saved scores of the leaderboard .
score
int
The score the user made
The score the user made