Save data to .CSV (c#)

Hello, i’m making a 2D game in which you have to click on baloon to destroy them.
I want to save some informations in a CSV file but i have some problems…

Currently my code is :

public void btnValidateSave()
{

nom = champsNom.text; //inputField.text value i want to save
prenom = champsPrenom.text; //inputField.text value i want to save
age = champsAge.text; //inputField.text value i want to save
classe = champsClasse.text; //inputField.text value i want to save

string filePath = @“/Saved_data.csv”;

File.WriteAllText(filePath, nom + “;” + prenom + “;” + age + “;” + classe );

//OpenMenu(1);

}

The problem is that every time i save data, the CSV file is replacing the last one, it’s not saving the last informations saved.

I want all data to be saved on this file. (on several lines)

Do you have any idea of what i can do ?

Thanks.

Firstly, please post code using tags so it’s formatted nicely.

You need to append to your file. Google it, you’ll get loads of examples.

Thank you my problem is resolved thanks to this link : c# - How to add new line into txt file - Stack Overflow

Can you please submit how the code looks like now?
I’m having the same issue but with no success.

The link is still valid and shows examples of how to do it. If you are still confused, please post your code (in your own thread) and explain what’s happening/not working.

Simple coding ,Read CSV file in Unity,::

Hey! The video is great–the only issue I’m having is that I can’t seem to find the correct relative file path to load one from my assets folder. Any help? I want this to work on other machines.

Also if you really want csv you should be using , not ; as your delimiter.
I tend to prefer tab delimited. Because a lot of times the data would contain commas.

@justinwgaines

“I can’t seem to find the correct relative file path to load one from my assets folder.”

You can get it with Application.dataPath (+ your sub folder after it). In editor it’s Assets folder, in game it’s the game data folder (read only).

You could also use Application.persistentDataPath instead.