- Home /
How can I read a text file using Resources.load?
I am trying to read a file and split it by comma. fileName is a public string. myFile is a public string. lines is a public string[]. The data in the file is this:
0.00000000,0.00000000,0.00000000,0.00000000,0.00000000,0.00000000,0.00000000,0.00000000,0.00000000,0.00000000,0.00000000,0.00000000,0.00000000,0.00000000,0.00000000,0.00000000,0.00000000,0.00000000,0.00000000,0.00000000,0.00000000,0.00000000,0.00000000,0.00000000,0.00000000,0.00000000,0.00000000,0.00000000,0.00000000,0.00000000,0.00000000,0.00000000,0.00000000,0.00000000,0.00000000,0.00000000,0.00000000,0.00000000,0.00000000,0.00000000,0.00000000,0.00000000,0.00000000,0.00000000,0.00000000,0.00000000,0.00000000,0.00000000,0.00000000,0.00000000,0.00000000,0.00000000,0.00000000,0.00000017,0.00001135,0.00027700,0.00280333,0.00956266,0.01018892,-0.00998891,-0.03118897,-0.02384511,-0.00292599,0.01880032,0.04093220,0.03775710,0.01302902,-0.02542765,-0.06850022,-0.04759452,0.01770965,0.05359425,0.06701109,0.01526797,-0.07725055,-0.06248632,0.03035413,0.05043085,-0.01032532,-0.02606330,0.03007799,0.02918039,-0.03373267,-0.04321082,0.00215665,0.03183192,0.02613451,0.00567460,-0.02468813,-0.03453672,0.00771780,0.03642097,0.00238402,-0.02820734,-0.00211923,0.02445256,0.00311997,-0.01842002,-0.01005592,0.00325619,
void Start()
{
fileName = $"Wave_Position_2_2_2";
}
void Update()
{
if (Input.GetKeyDown("s"))
{
myFile = Resources.Load<TextAsset>(fileName).text;
lines = myFile.Split(',');
}
}
Answer by CmdrZin · Dec 28, 2020 at 12:38 AM
https://docs.unity3d.com/ScriptReference/Resources.Load.html give an example. Your filename/path may be incomplete.
Your answer
