Tracking high score
One more thing that would be good to have in our game is tracking the player's high score. For this, we not only need to keep the high score of the current session, but then persist that data so it's preserved for the next time you play.
First, we'll make a UI element to display the current high score. It will be easiest to simply duplicate the ScorePanel we just made and modify it:
- Select the
ScorePanelinHierarchyand duplicate it (right-click and select the optionDuplicate). - Rename it
HighScorePanel. - Set the
Rect TransformtoLeft:-120,Top:50,Right:120,Bottom:-50. - Rename child
ScoreTitletoHighScoreTitle. - Change its
TexttoHigh Score. - Rename child
ScoreValuetoHighScoreValue. - Set
Font StyletoBold and Italic, andColorto a pale orange (#FF9970FF).
The current high score will be kept in an ordinary C# object class named PlayerProgress. We can define that now. In your Scripts folder, create a new C# script named PlayerProgress and open it for editing:
File: PlayerProgress...