- Home /
Question by
Arman-Mokammel · Jun 21, 2018 at 04:23 PM ·
androidresourcestxt
Read a specific line from a txt file in Android
I have a txt file in my resources folder and I want to read a random line from the file and show it somewhere. Here is my code:
string[] lines = System.IO.File.ReadAllLines (path); showtext.text = lines[Random.Range(0,lines.Length)];
It works pretty well on PC but does not on Android. I figured out that I got my 'path' wrong. Can any one help me?
Comment
Answer by MonkeyHood · Jun 24, 2018 at 05:32 AM
You can't find it because the Resources
folder does not exist in the apk. Instead, create a reference to a TextAsset
and assign it through the inspector.
public class MyClass : MonoBehaviour
{
public TextAsset TextFile;
}