0
0
Unityframework~10 mins

PlayerPrefs for simple data in Unity - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to save an integer score using PlayerPrefs.

Unity
PlayerPrefs.SetInt("score", [1]);
Drag options to blanks, or click blank then click option'
Ascore
BscoreValue
Cpoints
Dvalue
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name that is not defined.
Using a string instead of a variable.
2fill in blank
medium

Complete the code to retrieve the saved integer score from PlayerPrefs.

Unity
int savedScore = PlayerPrefs.[1]("score", 0);
Drag options to blanks, or click blank then click option'
AGetString
BGetInt
CGetFloat
DLoadInt
Attempts:
3 left
💡 Hint
Common Mistakes
Using GetString or GetFloat for an integer value.
Using a method that does not exist like LoadInt.
3fill in blank
hard

Fix the error in the code to save a float value for volume using PlayerPrefs.

Unity
PlayerPrefs.SetFloat("volume", [1]);
Drag options to blanks, or click blank then click option'
AvolumeLevel
B"volumeLevel"
CvolumeLevel.ToString()
Dvolume
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a string instead of a float variable.
Calling ToString() on the float variable.
4fill in blank
hard

Fill both blanks to save and then retrieve a boolean value using PlayerPrefs.

Unity
PlayerPrefs.SetInt("isMusicOn", [1] ? 1 : 0);
bool isMusicOn = PlayerPrefs.GetInt("isMusicOn", 1) [2] 1;
Drag options to blanks, or click blank then click option'
AisMusicOn
B==
C!=
DmusicOn
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to save a boolean directly.
Using wrong comparison operator.
5fill in blank
hard

Fill all three blanks to save a player's name and then retrieve it with a default value.

Unity
PlayerPrefs.SetString("playerName", [1]);
string name = PlayerPrefs.[2]("playerName", [3]);
Drag options to blanks, or click blank then click option'
AplayerName
BGetString
C"Guest"
Dplayer
Attempts:
3 left
💡 Hint
Common Mistakes
Using GetInt or GetFloat for strings.
Not providing a default value when retrieving.