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
ScorePanel
inHierarchy
and duplicate it (right-click and select the optionDuplicate
). - Rename it
HighScorePanel
. - Set the
Rect Transform
toLeft
:-120
,Top
:50
,Right
:120
,Bottom
:-50
. - Rename child
ScoreTitle
toHighScoreTitle
. - Change its
Text
toHigh Score
. - Rename child
ScoreValue
toHighScoreValue
. - Set
Font Style
toBold and Italic
, andColor
to 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...