I'm having an error with this script, which should load a .txt file, read in each line, and seperate that line into 7 variables. Have a look:
StreamReader sr = new StreamReader(Application.dataPath + "/" + "model.3dl");
string fileContents = sr.ReadToEnd();
sr.Close();
string[] lines = fileContents.Split('
');
for (int j = 0;j<lines.Length;j++) {
string[] loadData = new string[7];
loadData = lines[j].Split(':');
Debug.Log(loadData[1]);
}
Now, whenever I run the game, I get this error:
IndexOutOfRangeException: Array index is out of range.
Which points me to the Debug.Log line in the above script. Said script looks fine to me, perhaps I just need another pair of eyes to point out the problem. It's somewhat derived from the helpful answer to this question, with the exception that I converted it from JS to C#.
If the solution is biting me on the nose, please don't hesitate to tell me. If it's not so obvious, tell me anyways. I just want it to work. :)