Join Jesse Freeman for an in-depth discussion in this video Saving high scores, part of Unity 5 2D Essential Training (2015).
- View Offline
- Exercise Files
- At this point, we're now ready to keep track…of the high score.…Let's go back into our Game Manager…and open up the Game Script.…When the player dies,…we're gonna want to test that the time elapsed…is better than the best time we already have.…At the very end of OnPlayerKilled,…let's add the following condition.…If time elapsed is > best time,…we're gonna want to save this value out.…First, we're gonna set best time…to = the current time elapsed.…
Then we're gonna take advantage of something called…the PlayerPrefs.…This class allows us to save values…into Unity, similar to how cookies work in a web browser.…Here we're gonna save a float value,…we're gonna give it an I.D. of BestTime,…and we're gonna pass it in the value of BestTime.…Now, also, we're gonna wanna actually get a reference…to BestTime when we start the game.…This way, when the first game is over,…we already have the value of BestTime.…
In this case, let's go all the way up to the Start Method…and at the end, let's set the bestTime to = PlayerPrefs.…
Super Zombie Runner riffs off the popular endless runner genre: a one-button casual game that's not only fun to play but exciting to build. The focus of the work is a reusable code base that you can extend and make your own, while learning the basics of object pooling, supporting multiple screen resolutions, tracking scoring, and multi-platform publishing. Along the way, Jesse covers key Unity features, such as working with sprites, creating animations, and leveraging the UI components.
- Working with sprites and animation
- Creating the player
- Spawning GameObjects
- Adding obstacles and collisions
- Building the game objects and logic
- Managing game state
- Creating pixel-perfect cameras
- Designing for multiple screen resolutions
- Adding scores
- Optimizing performance
- Publishing to desktop, web, and mobile platforms
Skill Level Intermediate
1. Working with Sprites
2. Creating Repeating Textures
3. Creating Obstacles
4. Object Pooling
5. Creating the Player
6. Setting Up the Game
7. Adding UI
8. Creating More Obstacles
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.