Hello,
I have a script that creates, and writes into a text file. My question is, how can I search in the file? For example, I want to edit the line under the line that contains Level2. How can I do it?
Here is my code:
import System.IO;
var filePath = "data.txt";
function Start()
{
if (!File.Exists(filePath))
{
CreateFile();
}
}
function CreateFile()
{
var sw : StreamWriter = new StreamWriter(filePath);
sw.WriteLine("profile");
sw.WriteLine("Level1");
sw.WriteLine("unlocked");
sw.WriteLine("Level2");
sw.WriteLine("Locked");
sw.Flush();
sw.Close();
print ("Done");
}
So if I would like to enable level 2, than I should search for level 2, then rewrite the 2 lines? The code above is just an example, my full file will be 150+ lines long.
– DreekaNo, you'd just rewrite the entire file. Looks to me like you should just be using PlayerPrefs anyway.
– WazHow exactly would this look like? Find(ParenObject ChildObjectName ) ?
– paul200642