B. PlayerPrefs.SetFloat requires a string value, not a number.
C. The key "health" must be an integer.
D. PlayerPrefs.Save() must be called to ensure data is written.
Solution
Step 1: Check PlayerPrefs.SetFloat usage
SetFloat correctly saves float values with a string key.
Step 2: Understand importance of PlayerPrefs.Save()
Without Save(), data may not be written immediately and can be lost on crash.
Final Answer:
PlayerPrefs.Save() must be called to ensure data is written. -> Option D
Quick Check:
Always call Save() after setting PlayerPrefs [OK]
Hint: Call PlayerPrefs.Save() after setting values [OK]
Common Mistakes:
Thinking SetFloat can't save floats
Believing keys must be integers
Confusing data types for PlayerPrefs
5. You want to save a player's name and highest score so progress is kept between sessions. Which approach correctly saves and retrieves this data in Unity?
hard
A. PlayerPrefs.SetString("playerName", "Alex"); PlayerPrefs.SetInt("highScore", 500); PlayerPrefs.Save(); string name = PlayerPrefs.GetString("playerName"); int score = PlayerPrefs.GetInt("highScore");
B. PlayerPrefs.SaveString("playerName", "Alex"); PlayerPrefs.SaveInt("highScore", 500); string name = PlayerPrefs.LoadString("playerName"); int score = PlayerPrefs.LoadInt("highScore");
C. PlayerPrefs.Set("playerName", "Alex"); PlayerPrefs.Set("highScore", 500); string name = PlayerPrefs.Get("playerName"); int score = PlayerPrefs.Get("highScore");
D. PlayerPrefs.SetString("playerName", "Alex"); PlayerPrefs.SetInt("highScore", 500); string name = PlayerPrefs.GetString("playerName"); int score = PlayerPrefs.GetInt("highScore");
Solution
Step 1: Identify correct PlayerPrefs methods for saving data
Use SetString for strings and SetInt for integers, then call Save() to write data.
Step 2: Retrieve data with GetString and GetInt methods
These methods get the saved values correctly.
Final Answer:
PlayerPrefs.SetString("playerName", "Alex"); PlayerPrefs.SetInt("highScore", 500); PlayerPrefs.Save(); string name = PlayerPrefs.GetString("playerName"); int score = PlayerPrefs.GetInt("highScore"); -> Option A
Quick Check:
Set + Save then Get methods for persistence [OK]
Hint: Set values, call Save(), then Get values to persist data [OK]
Common Mistakes:
Using non-existent SaveString or LoadInt methods
Forgetting to call PlayerPrefs.Save()
Using generic Set or Get methods incorrectly
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.