I am currently trying to create a function that works with a StreamReader to read a line of text, parse the text, and then instantiate a text variable prefab to immediately assign that text for each line within the text file.
I want to use the values that are split into the temps[ ] array as the values assigned to the text prefabs.
I don’t know how to assign these values and any help or ideas would be greatly appreciated.
Edit: The text input lines look something like this:
Coke,24.99,16
Sprite,23.99,18
public void displayTable()
{
// temp variables
string[] temps;
// count lines
var enumLines = File.ReadLines(saveDataPath, Encoding.UTF8);
// have reader read the lines within save file
try
{
// instantiate reader
using (StreamReader sr = new StreamReader(saveDataPath))
{
// iterate over lines
string line;
while ((line = sr.ReadLine()) != null)
{
// parse lines into variables
foreach(var lines in enumLines)
{
Debug.Log(lines);
temps = lines.Split(',');
// duplicate objects for use in table
Instantiate(pfItem, new Vector3(0, 0, 0), Quaternion.identity);
Instantiate(pfOrderCost, new Vector3(0, 0, 0), Quaternion.identity);
Instantiate(pfOrderQuant, new Vector3(0, 0, 0), Quaternion.identity);
}
}
}
}
catch (Exception e)
{
Console.WriteLine("The file could not be read:");
Console.WriteLine(e.Message);
}
}