Guys... A simple question that probably a few of you had when you first started... If I have a Player.Prefs storing an option for the languaje selection...(i.e English / Spanish) and after that selection I have to display 2 GUI buttons, let´s say YES / NO vs SI / NO; after I define the button (if (GUI.Button, etc), where I have to put the text that is going to be inside of it, can I open a {, put an if and the var with the Player.Prefs stored there? or it has to be placed prior to the GUI button instance? (does it make sense?) Thanks!
Sure... I want to know if somethin like this is possible: Code (CSharp): If (GUI.Button(new Rect(0,0,10,10), { if (lSel ==1)"SOUND"; if (lSel ==2)"SONIDO"; })) {} (lSel is the var where I have stored the PlayerPrefs) Instead of if (lSel ==1) >> define GUI.Button And if (lSel ==2) >> define GUI.Button again
Localisation should be data focused, not hardcoded. If you had a localisation system which loaded a file, with a key string and a key value pair, you use that to set the string. LocalisationSystem.GetNamedString(mySoundStringKey); Obviously writing that system will be a lot of work, but it's well worth it. Plus, you can then use it for any other game you make
I +1 what A.Killingbeck is saying. To expand on that I'd create two XML files that holds string information in fragments Example: GameName_UI_ENG.xml <fragment fragmentId="startGame"> <text>Start Game</text> </fragment> GameName_UI_ESP.xml <fragment fragmentId="startGame"> <text>Iniciar Juego</text> </fragment> then write a method that pulls data from XmlDocument.
are you trying to select and language and then a yes and No buttons to either confirm selection or close and select again??
I`m C# only but this is what I would do , but again im not sure exactly what your trying Code (CSharp): using UnityEngine; using System.Collections; public class LanguageSelectionExample : MonoBehaviour { int languageSelection; bool drawSpanish = false, drawEnglish = false; const string _myLanguage = "myLanguage"; public GUIStyle englishLanguageSelectionButton,spanishLanguageSelectionButton; void Start () { languageSelection = PlayerPrefs.GetInt ("myLanguage",0); if (languageSelection == 2) { drawEnglish = true; } else { drawEnglish = false; } if (languageSelection == 3) { drawSpanish = true; } else { drawSpanish = false; } } void Update () { } void OnGUI() { if (Application.loadedLevel == 0) { GUI.skin.button = englishLanguageSelectionButton; if (GUI.RepeatButton (new Rect (Screen.width / 2.75f, Screen.height / 5f, Screen.width / 3.8f, Screen.height / 6.3f), "")) { PlayerPrefs.SetInt ("myLanguage", 2); PlayerPrefs.Save (); Application.LoadLevel (2); } GUI.skin.button = spanishLanguageSelectionButton; if (GUI.RepeatButton (new Rect (Screen.width / 2.75f, Screen.height / 1.5f, Screen.width / 3.8f, Screen.height / 6.3f), "")) { PlayerPrefs.SetInt ("myLanguage", 3); PlayerPrefs.Save (); Application.LoadLevel (3); } } if (Application.loadedLevel == 1) { if (drawEnglish == true) { } if (drawSpanish == true) { } } } }
Dublinjonny, I believe he's trying to implement a feature to change the language on the entire application and asking for help on how he would handle hot-swapping the text from language to language. Moreover, your reply is still an example of hardcoding localization handlers. Not to mention being a nightmare to add or remove languages. A more practical example would be to load up a language file dynamically: Code (CSharp): //Be sure to import xml libs---- using system.xml; //------------------------------------------ XMLDocument LangFile; void Start(){ //Make sure you can load the correct language file needed for the application if(bGetLangConfig()){ //Continue with other stuff } } bool bGetLangConfig(){ try{ string sysLang = PlayerPrefs.GetString("Language"); //Load the language file LangFile = XmlDocument.Load("[Resources]/languageConfigs/"+sysLang+".xml"); }catch(err){ //stuff } } string getText(string nodeName){ if(LangFile != null){ return LangFile.GetElementById(nodeName); }else{ return ""; } } void OnGUI(){ GUI.Button(someRect,getText("startGame")); } It's worth noting that I skipped some necessary xml steps pertinent to loading and reading docs to save on time and space. But I assume you can just fish around the MSDN to find them.