I'm making a game in Unity with an editor level that writes the level data in a .txt
My problem is that changes to the file are not applying correctly because I only can see them when I restart the game.
When the player creates a new level i use this:
TextAsset txtFile = Resources.Load<TextAsset>("Levels");
StreamWriter streamWriter = new StreamWriter(new FileStream("Assets/Resources/" + levelsManager.filename + ".txt", FileMode.Truncate, FileAccess.Write));
And at the end of the method I close the StreamWriter.
streamWriter.Flush();
streamWriter.Close();
streamWriter.Dispose();
Moreover if the user creates multiple levels, only the last one is saved.
Changing the filemode to apend does not work because after restarting the game and creating a level it also creates again the stored levels.
¿Is there a way of refreshing the document so I don't have to restart the game everytime I create a level?
Thank you in advance.