- Home /
READ/WRITE Variable to text file
i have a text file in my 'resources/' folder and it has the following text: Name: Gender:
im trying to make it so that in a GUI text field you can enter the answers to these... then hit save and it will write it to a file called playerinfo.txt which is in my Resources folder.. how would achieve this?
Answer by robertbu · Feb 18, 2014 at 06:26 AM
Writing to the Resources folder will only work in the Editor. The Resources folder does not exist in platform builds. You can use Application.persistentDataPath as a place to write files on many platforms, or you can use PlayerPrefs. If you are trying to write array data to PlayerPrefs, take a look at this wiki script:
If you are doing this in an Editor script for some kind of configuration interface you will use in building the game you can write to the resources folder, but you need the relative path to the place you want to put it starting with Assets.
ok lets say i use System.IO....etc how would i do it then?
You can use any .NET I/O functions to write anywhere you are allowed to write. And where you are allowed to write changes by platform. A Windows build can write just about anywhere. A Web build cannot write on the machines that are playing the game. If you want to have the greatest change of writing across platforms, use Application.persistentDataPath as the path to write.
But given you short description, PlayerPrefs seems like a much better choice than writing an external data file.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Write and read text files with c# 1 Answer
Opening a GUI text file 0 Answers
How to split up a Text Object into Text Objects of size 1 char at the exact same position? 2 Answers