Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Game Development How to Make a Video Game Build and Share a Unity Game Go Make Games

Jack Beauchamp
Jack Beauchamp
2,411 Points

Can someone please help me add a simple high score to the frog game

It would be very helpful if I could get the code for it and step by step instructions as I read about player prefs which I heard are the way to go but I don't get them also I need the code in c#.

2 Answers

Seth Kroger
Seth Kroger
56,413 Points

PlayerPrefs stores data in key/value pairs. Key/value pairs are a quite common structure in programming. Each key is unique, and has it's own associated value. You can think of a key as a label. PlayerPrefs using strings for keys and you can use the name of the key to get and set the value. It has methods to get and set a value as a float, integer or string.

highScore = PlayerPrefs.GetInt("HighScore", 0);  // get the value for the key HighScore, defaulting to zero if not there.

 // ...play the game...

if (score > highScore) {
   PlayerPrefs.SetInt("HighScore", score);  // set the value for the key HighScore
}
Jack Beauchamp
Jack Beauchamp
2,411 Points

Sorry for the late thanks but that helped a lot.