Reputation: 101
I am extracting some information from several text files in different folders. For that purpose I created an application with several Input Fields to write the folders' name that I want to go. Everything went well in Editor Mode.
However when I build the project and run the ".exe" file created, it can't find the text files I want. I show below the code I am using to extract the files. The first data.path is the one I used on my Editor and worked well while the second (commented) data.path is one trial that I tried by placing my folder on the ".exe" Data folder. But it didn't work...
data.motion = input_text;
data.subjectName = input_text2;
data.path = "C:/Users/Matias/Desktop/Acquisition_Data/Kinect1/" + data.subjectName + "/" + data.motion + ".txt";
/*data.path = Application.dataPath + "/Acquisition_Data/Kinect1/" + data.subjectName + "/" + data.motion + ".txt";*/
data.lines = System.IO.File.ReadAllLines(data.path);
I can't get any explanation why any of these methods work when I build the application.
I am using C# and running on Windows10.
Upvotes: 0
Views: 5043
Reputation: 1492
If your texts are static (never more, never less) then you could simply use TextAsset : http://docs.unity3d.com/ScriptReference/TextAsset.html
Upvotes: 0
Reputation: 125435
You really can't do that because Unity encodes the files into binary form and renames them too. You have to move the txt file after building then you can access it directly. I answered similar question like this yesterday so I will post the link to the answer. Do do things I mentioned in this answer below.
Unity3D loading resources after build
Then remove the Texture2D stuff and replace File.ReadAllBytes(imagePath);
with System.IO.File.ReadAllLines(data.path);
and that should work.
Upvotes: 1
Reputation: 563
This is the problem of using Relative path or using absolute path. If absolute path doesn't work try relative path. eg. ../name.txt
put your name.txt in asset or somewhere you can point with.
Upvotes: 0