So, what I want to do is this:
Read data from a file “data.txt”. I want to then pick a random line of that data, say line 3. At the moment, I’m reading the whole file. Can I just read line 3 of that file?
var fileName = “data.txt”;
// read from filename
var sr = new StreamReader(Application.dataPath + "/" + fileName);
var fileContents = sr.ReadToEnd();
sr.Close();
// put data from filename into a variable
// var mydata = fileContents.Split("
"[0]);
var mydata = fileContents;
// pick a random number between 1 and 10
var myrandom = Random.Range(1,10);
// I know this bit isn’t right, but what I want is
print (line myrandom of mydata);
It’s in Javascript as that’s more human-readable for me. I just can’t get my head around C.
Also, sorry I’m really new to all of this. I don’t even know how to use tags on this website to show quoted code! Please help!!