Skip to content

Instantly share code, notes, and snippets.

@tanyuan
Created January 7, 2017 19:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tanyuan/0cc96d5728d3f163d11769ad2a3550a7 to your computer and use it in GitHub Desktop.
Save tanyuan/0cc96d5728d3f163d11769ad2a3550a7 to your computer and use it in GitHub Desktop.
Unity read & write text files.
using System.IO;
string path = "Assets/file.txt";
// Write to file
File.AppendAllText(path, System.String.Format("{0} {1} {3}\n", var1, var2, var3));
// Read from file
StreamReader sr = new StreamReader(path);
for (int i = 0; !sr.EndOfStream; i++) {
string line = sr.ReadLine ();
string[] Splitted = line.Split(new char[] {' '}, System.StringSplitOptions.RemoveEmptyEntries);
record.Add (new Vector3 (float.Parse (Splitted [0]), float.Parse (Splitted [1]), float.Parse (Splitted [2])));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment