Answer the question
In order to leave comments, you need to log in
Why is JSON file not showing on Android?
I decided to use JSON files to localize the game. Everything works fine in the Unity Editor, but when I start the game on Android, all the text disappears. Why is this happening?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
using UnityEngine.UI;
public class LangSystem : MonoBehaviour
{
private string json;
public static lang lng = new lang();
void Awake()
{
if (!PlayerPrefs.HasKey("Languages"))
{
if(Application.systemLanguage == SystemLanguage.Russian || Application.systemLanguage == SystemLanguage.Belarusian)
{
PlayerPrefs.SetString("Languages", "ru_RU");
} else if(Application.systemLanguage == SystemLanguage.Ukrainian)
{
PlayerPrefs.SetString("Languages", "ua_UKR");
} else
{
PlayerPrefs.SetString("Languages", "eng");
}
}
LangLoad();
}
void LangLoad()
{
#if UNITY_ANDROID && !UNITY_EDITOR
string path = Path.Combine(Application.streamingAssetsPath, "Language/" + PlayerPrefs.GetString("Languages") + ".json");
WWW reader = new WWW(path);
while(!reader.isDone) { }
json = reader.text;
#endif
#if UNITY_EDITOR
json = File.ReadAllText(Application.streamingAssetsPath + "/Language/" + PlayerPrefs.GetString("Languages") + ".json");
lng = JsonUtility.FromJson<lang>(json);
#endif
}
public void SwitchLang(string name)
{
switch (name)
{
case ("UA"):
PlayerPrefs.SetString("Languages", "ua_UKR");
break;
case ("RU"):
PlayerPrefs.SetString("Languages", "ru_RU");
break;
case ("ENG"):
PlayerPrefs.SetString("Languages", "eng");
break;
}
LangLoad();
}
}
public class lang
{
public string[] Menu = new string[3];
public string[] Options = new string[5];
public string[] NameDifficult = new string[3];
public string[] DiscriptionDifficult = new string[3];
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question