High score and persisting data

Pretty much every game has some sort of scoring system. You will now learn how to write simple code that calculates the score based on the distance the player has traveled since the start of the level. We will then use this score value and store it in Unity's PlayerPrefs class to make sure that the value is remembered between sessions. PlayerPrefs is a very useful built–in Unity class that allows us to store and access data between Unity sessions.

Let's write the following method in the Player class:

We have finally come to a reallife example of a method that returns something. As you can see, the GetDistance() ...

Get Learning C# 7 By Developing Games with Unity 2017 - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.