Created
January 7, 2017 19:40
-
-
Save tanyuan/0cc96d5728d3f163d11769ad2a3550a7 to your computer and use it in GitHub Desktop.
Unity read & write text files.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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