0
0
Unityframework~10 mins

File-based save system 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 declare the file path variable for saving data.

Unity
string filePath = Application.persistentDataPath + [1];
Drag options to blanks, or click blank then click option'
A"/savefile.json"
B"savefile.json"
C"/savefile"
D"savefile"
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting the slash '/' before the file name.
2fill in blank
medium

Complete the code to write a JSON string to a file.

Unity
File.WriteAllText([1], jsonData);
Drag options to blanks, or click blank then click option'
AApplication.persistentDataPath
BjsonData
CfilePath
DsaveFile
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the data string instead of the file path.
3fill in blank
hard

Fix the error in reading the file content into a string.

Unity
string jsonData = File.[1](filePath);
Drag options to blanks, or click blank then click option'
AReadFile
BReadText
CReadAllLines
DReadAllText
Attempts:
3 left
💡 Hint
Common Mistakes
Using ReadAllLines which returns a string array instead of a string.
4fill in blank
hard

Fill both blanks to deserialize JSON data into a PlayerData object.

Unity
PlayerData player = JsonUtility.[1]<[2]>(jsonData);
Drag options to blanks, or click blank then click option'
AFromJson
BToJson
CPlayerData
DSaveData
Attempts:
3 left
💡 Hint
Common Mistakes
Using ToJson which converts object to JSON string instead of the opposite.
5fill in blank
hard

Fill all three blanks to save player score to a JSON file.

Unity
string jsonData = JsonUtility.[1](playerData);
File.[2]([3], jsonData);
Drag options to blanks, or click blank then click option'
AToJson
BWriteAllText
CfilePath
DReadAllText
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up ToJson and FromJson methods.
Using ReadAllText instead of WriteAllText for saving.