Save chosen language
I want to add multiple languages in my Game, so that the user can chose in the main menu his prefered language. The user already can chose a supported language and everything works fine, I just dont know how to save the chosen language over scenes or even forever. Right now the user have to chose the language in every single scene.
I heard from PlayerPrefs, but I really dont know how to save a language there.
Answer by Dave-Carlile · Sep 21, 2015 at 08:38 PM
This sort of thing is pretty much exactly what PlayerPrefs
was designed for. I assume you have some sort of value that identifies which language the player selected from the menu? That's the value you would save in PlayerPrefs.
I would create a function that enables the selected language:
void SelectLanguage(int languageId)
{
// do the stuff to enable the language based on the language id
}
When the user selects a language from the menu...
int languageId = the id the user selected from the menu
SelectLanaguage(languageId)
PlayerPrefs.SetInt("Language", languageId);
And on startup you need to also enable that language
void Start() // one some game initialization object
{
int langageId = PlayerPrefs.GetInt("Language");
SelectLanguage(languageId);
}
This is mostly pseudo-code so it may or may not work as is. The point is, create a single function that enables the appropriate language, and call that same function from both the menu when the user changes the languages, as well as during startup.
Your answer
Follow this Question
Related Questions
I need help with boss design. I am new to coding so any help would be nice. 0 Answers
Character moves without arrow keys 0 Answers
I was trying to make my game in unity but I got stuck while making "game over" part. please help! 0 Answers
call the current method, using some sort of keyword? for self reference 1 Answer