Quantcast
Channel: Questions in topic: "localization"
Viewing all articles
Browse latest Browse all 210

Localization over scenes

$
0
0
I want to add multiple language support to my game and currently I'm using Smart Localization from the Assets Store. I have 4 buttons in my first scene for switch the language and if a button is selected, the float "language" changes to a value between 1 and 4 and the language changes like it should. If you continue to the next scene, "language" will be saved in PlayerPrefs and if the script is loaded again, "language" will get the value from PlayerPrefs, so it should display the text in the language that has been selected before but it does'nt, the textfields are just empty although "language" has a valid value(1-4) that should change the language. Any ideas why? Heres my code: public class Test : MonoBehaviour { public Text PlayTxt, BackTxt, EarthTxt, HealthTxt, MenuTxt, MissingTxt, RestartTxt, DamageTxt; public string playKey = "Play"; public string earthKey = "Earth"; public string healthKey = "Health"; public string menuKey = "Menue"; public string missingKey = "Missing"; public string restartKey = "Restart"; public string damageKey = "Damage"; public string backKey = "Back"; public float language; void Start(){ if(PlayerPrefs.HasKey ("language")) { language = PlayerPrefs.GetFloat ("language"); } } void Update(){ if (language <= 1) { LanguageManager.Instance.ChangeLanguage ("en"); } if (language == 2) { LanguageManager.Instance.ChangeLanguage ("de"); } if (language == 3) { LanguageManager.Instance.ChangeLanguage ("es"); } if (language == 4) { LanguageManager.Instance.ChangeLanguage ("tr"); } PlayTxt.text = "" + LanguageManager.Instance.GetTextValue(playKey); BackTxt.text = "" + LanguageManager.Instance.GetTextValue(backKey); EarthTxt.text = "" + LanguageManager.Instance.GetTextValue(earthKey); HealthTxt.text = "" + LanguageManager.Instance.GetTextValue(healthKey); MenuTxt.text = "" + LanguageManager.Instance.GetTextValue(menuKey); MissingTxt.text = "" + LanguageManager.Instance.GetTextValue(missingKey); RestartTxt.text = "" + LanguageManager.Instance.GetTextValue(restartKey); DamageTxt.text = "" + LanguageManager.Instance.GetTextValue(damageKey); } public void engl(){ LanguageManager.Instance.ChangeLanguage ("en"); language = 1; } public void de(){ LanguageManager.Instance.ChangeLanguage ("de"); language = 2; } public void es(){ LanguageManager.Instance.ChangeLanguage ("es"); language = 3; } public void tr(){ LanguageManager.Instance.ChangeLanguage ("tr"); language = 4; } void OnDestroy(){ PlayerPrefs.SetFloat ("language", language); } }

Viewing all articles
Browse latest Browse all 210

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>