0
\$\begingroup\$

I am making a simple hangman game, I have a small list of words in a .txt file separated by new lines. I put the word list into the assets folder. How can I find the path to the word list so I can use:

string[] wordlist = System.IO.File.ReadAllLines("pathToFile");

Or is there another solution of converting the word list into a string array?

\$\endgroup\$
  • \$\begingroup\$ docs.unity3d.com/Manual/StreamingAssets.html. Like the answer I have little to no exp with Unity, found this link with a search engine, as you should be doing before asking \$\endgroup\$ – realUser404 Dec 28 '16 at 16:56
  • \$\begingroup\$ Please consider researching your question, before posting. Questions that show no research effort may receive down votes. \$\endgroup\$ – Gnemlock Dec 28 '16 at 22:53
0
\$\begingroup\$

Use the Streamreader to load in the text in unity or set it as a text asset and parse it directly. This forum post should help give you an idea of what to do:

https://forum.unity3d.com/threads/read-from-textasset-line-by-line.327422/

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ This actually worked better for me cause the unity compiles my text file. This way I can access it even if it's encrypted. \$\endgroup\$ – user95747 Dec 30 '16 at 16:10
  • \$\begingroup\$ This answer would be better if it included at least a summary of the method(s) suggested in the linked thread, so a user doesn't need to read through all the back-and-forth discussion at the link to follow it, and so that the answer is robust even if the linked thread is deleted or changes address. It would also be good to clarify that the thread recommends not using a StreamReader, but instead using Unity's TextAsset functionality. \$\endgroup\$ – DMGregory Dec 31 '16 at 21:34
2
\$\begingroup\$

I have little experience with Unity, but it appears as though you can use Application.dataPath to obtain the correct path.

Here it is at the API.

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy