I have a text file contained of values separated with coma. I read it by C# with TextAsset and parsing the values by split. My program is working when I have a produced saved text file. This file is produced with a device and the problem is that I want to read it when it being written simultaneously. But unity will crash when I try to run the device and unity at the same time. I tried to make a delay between writing and reading by WaitForSeconds or Thread.Sleep but none of them worked
would you please help me how can I read an open text file when the file is during being written.
the data are like:
0,-0.0021,0.0026,-0.0019
0.01,-0.0017,0.0036,-0.0028
0.02,-0.0016,0.0040,-0.0037
and my C# code is:
public float t = 0f;
public float X = 0f;
public float Y = 0f;
public float Z = 0f;
public TextAsset data;
void Update ()
{
string[] dataLines = data.text.Split('
‘);
string dataPairs = new string[dataLines.Length];
int lineNum = 0;
foreach (string line in dataLines)
{
dataPairs[lineNum++] = line.Split(’,');
}
for (int i = 0;i<=lineNum;i++)
{
t = float.Parse (dataPairs*[0]);*
_ X = float.Parse (dataPairs*[1]);_
_ Z = float.Parse (dataPairs[2]);
Y = float.Parse(dataPairs[3]);
transform.position = new Vector3(X,Z,Y);
}*_
* }*
}