unity3d - Unity game localization c# -
i want add multiple language support game , i'm using smart localization assets store. have 4 buttons in first scene switch language , if button selected, float "language" changes value between 1 , 4 , language changes should. if continue next scene, "language" saved in playerprefs , if script loaded again, "language" value playerprefs, should display text in language has been selected before does'nt, textfields empty although "language" has valid value(1-4) should change language. ideas why?
heres 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); } }
Comments
Post a Comment