5. You want to save multiple player stats (score, level, health) in a file and load them later. Which approach correctly combines JSON serialization and file saving in Unity?
hard
A. Save each stat as a separate text file using File.WriteAllText without JSON
B. Serialize stats manually to a string and save using File.ReadAllText
C. Create a PlayerStats class with fields, serialize it with JsonUtility.ToJson, then save with File.WriteAllText using Application.persistentDataPath
D. Use JsonUtility.FromJson to save data and File.WriteAllText to load data
Solution
Step 1: Use a class to hold multiple stats
A class like PlayerStats with fields score, level, health organizes data for easy serialization.
Step 2: Serialize and save correctly
JsonUtility.ToJson converts the class to JSON string; File.WriteAllText with Application.persistentDataPath saves it safely.
Final Answer:
Create a PlayerStats class with fields, serialize it with JsonUtility.ToJson, then save with File.WriteAllText using Application.persistentDataPath -> Option C
Quick Check:
Class + JsonUtility + WriteAllText + persistentDataPath = correct [OK]
Hint: Use class + JsonUtility + persistentDataPath to save/load data [OK]
Common Mistakes:
Saving stats separately without JSON causes complexity
Mixing up ReadAllText and WriteAllText roles
Using FromJson for saving instead of loading
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.