Professional Documents
Culture Documents
Lab 5 - Fruit Picker p3 - Updated
Lab 5 - Fruit Picker p3 - Updated
Lab 5 - Fruit Picker p3 - Updated
Picker: part 3
INFO 4328 – Game Design & Development
(DIS/KICT)
Score Counter
Score Counter
Set the anchor to top-right and
readjust the text position, and
the text.
Adding
Points to
Each
Caught
Fruit
When a collision happens between the fruit and the basket, the score will
Be be updated.
Open Open the FruitPicker script and at the top, add “using TMPro;”.
Create Create a new private int score variable and initialize it in Start() as score = 0;
Adding Points to Each Caught Fruit
• Add an Awake
method in it.
Add
• Also, add the
following code in
Add Update.
Some Explanation…
Awake() is a built-in Unity MonoBehaviour method
(like Start() or Update()) that happens when this so Awake()always occurs before Start().
instance of the HighScore class is first created.
PlayerPrefs is a dictionary of values that are referenced through keys (that is, unique strings). In this
case, you're referencing the key HighScore.
This usage of PlayerPrefs enables the FruitPicker high score to be remembered on this machine, and
the high score will survive stopping playback, quitting Unity, and even restarting your computer.