- Home /
creating txt file
is it possible? to create a file. Like saving some information for the future use of the game, so later the txt file can be loaded and the information used? how would one do that? what classes/functions could be used to do that? thanks
Answer by Mike 3 · May 16, 2010 at 04:39 PM
you'll want to be using something along the lines of this: http://msdn.microsoft.com/en-us/library/system.io.file_members.aspx
WriteAllText is a good bet for writing to a file, takes a file path and a string to put in it
ow. I must admit I'm not a good programmer at all. Seems weird when I'm looking at the page you pointed me to. Don't unity have some functions that could help people with the above problem? (I acknowledge that I might even ask the wrong question, but you probably know what I'm trying to learn here).
@dot: Those are the functions that Unity uses. Unity program$$anonymous$$g is based on $$anonymous$$ono/.NET.
Theres not a lot to it... System.IO.File.WriteAllText("C:\test.txt", "abc"); ... will put abc into a file called test.txt for example
I get an error when using this: 'WriteAllText' is not a member of 'System.IO.File'.
?
Answer by Eric5h5 · May 16, 2010 at 05:40 PM
If all you want to do is save the game state, using PlayerPrefs is simpler than messing with files.
no. actually I want to save a lot more than just, what I imagine, hides behind the term of "game state". I need to save strings of text or numbers, which could be read later.
@dot: PlayerPrefs can save strings of text or numbers with no problems, and read them later. Do you want the files to be read outside Unity? In that case PlayerPrefs wouldn't be appropriate.
I guess both answers do it then. Thanks Eric. I'll let you know once I build something that you helped me with. Peace
Your answer
Follow this Question
Related Questions
How to script a Save/Load option on IPhone? 1 Answer
Saving Game Problem 1 Answer
PlayerPrefsX - Not Saving? 1 Answer
Best way to save procedural world/mesh? 0 Answers
Save and load data with Javascript... 0 Answers