Reading in from a text file (.txt) when deploying to Android devices.
For the game I'm making for Android, I'm trying to make a custom language setting and in order to do so I was planning on having a dictionary structure that would read in both keys and words from different text files into the game. the problem is, even though this works flawlessly on the computer, I'm still having trouble accessing the text files when it deploys to Android, since apparently it never finds the text files. When the game loads, no text at all is displapyed on the screen. I've also tried to use Resources.Load, but it has given me similar results. Here's some code for it:
Just in case, the file "PokemonNames.txt" is located in the "Assets" folder.
FileInfo file;
public Text IOText;
private void Start()
{
#if UNITY_EDITOR
file = new FileInfo(Application.dataPath + "\\" + "PokemonNames.txt");
ReadStuff();
#elif UNITY_ANDROID
file = new FileInfo(Application.persistentDataPath + "\\" + "PokemonNames.txt");
ReadStuff();
#endif
}
void ReadStuff()
{
#if UNITY_EDITOR
StreamReader reader = File.OpenText(Application.dataPath + "\\" + "PokemonNames.txt");
#elif UNITY_ANDROID
StreamReader reader = File.OpenText(Application.persistentDataPath + "\\" + "PokemonNames.txt");
#endif
while (!reader.EndOfStream)
{
IOText.text += (reader.ReadLine() + '\n') ;
}
reader.Close();
}
Your answer
Follow this Question
Related Questions
Directory.GetFiles() not returning anything in Android build 0 Answers
Saved folders (Application.persistentDataPath) showing on Android device but not in windows explorer 2 Answers
Take a Picture and Save Using Camera App 0 Answers
Animation stopping object rendering on Android device 1 Answer
problem lightmap 1 Answer