EDIT: When i fixed the problem, i delete this edit.
Hello Everyone!
I need help storing information in a JSON, as I am quite inexperienced in the subject.
When my game first starts, I create a JSON file that is empty. When it gets to the main menu, I check if the JSON is empty or not.
If it is empty, it opens a panel where you enter your name to save that information in the JSON.
In the panel, the player enters his name and presses the create button. I have created a function that gets the name entered by the user.
All this works correctly.
I have a String variable with the name and a DateTime with the creation date. But how do I store that information in the JSON? I have no idea
public void createProfile()
{
string namePlayer;
namePlayer = nameInputField.text;
DateTime currentDateTime = DateTime.Now;
//HOW TO DO ?
string fileJSON = JsonUtility.ToJson(namePlayer);
System.IO.File.WriteAllText(Application.persistentDataPath + "/playerData/profileGame.json", fileJSON);
Debug.Log(namePlayer);
Debug.Log(currentDateTime.ToString());
}
I know how JSON works, but not so much in C#.
The idea is to have a structure like this
{
"name": "Vengarl",
"lastSave": "2023...",
"object": {
"a": "b",
"c": "d"
}
}