Thursday, October 17, 2019

c# - How to read a data from text file in unity


Can anybody help me out with giving the steps needed for reading data from the text file in unity and how can the script be added.



Answer



C# Version.


using System.IO;

void readTextFile(string file_path)
{
StreamReader inp_stm = new StreamReader(file_path);


while(!inp_stm.EndOfStream)
{
string inp_ln = inp_stm.ReadLine( );
// Do Something with the input.
}

inp_stm.Close( );
}


EDIT: (Fixed an error on line 9; changed "stm.ReadLine();" to "inp_stm.ReadLine();")


No comments:

Post a Comment