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

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...