To save and load the player data using PlayerPrefs, follow these steps:
- Delete the C# script called Player.
- Edit the C# script called UpdateScoreText by replacing the Start() method with the following code:
void Start(){
Text scoreText = GetComponent<Text>();
int scoreCorrect = PlayerPrefs.GetInt("scoreCorrect");
int scoreIncorrect = PlayerPrefs.GetInt("scoreIncorrect");
int totalAttempts = scoreCorrect + scoreIncorrect;
string scoreMessage = "Score = ";
scoreMessage += scoreCorrect + " / " + totalAttempts;
scoreText.text = scoreMessage;
}
- Now, edit the C# script called IncrementCorrectScore by replacing the Start() method with the following code:
void Start () {
int newScoreCorrect = 1 + PlayerPrefs.GetInt("scoreCorrect");
PlayerPrefs.SetInt("scoreCorrect", newScoreCorrect);
}
- Now, edit the C# script called IncrementIncorrectScore...