Hello, I am creating a mobile game in unity, I was stuck in the part of saving the user settings for example if in the main menu the user presses a button to deactivate the music, vibration or language change I want to start the game in another scene the configuration that was made in the menu is conserved and thus close the game when the configuration is re-entered the game as it was chosen by the user, I read that I could do it with Playerprefs, only be used to save and load score, in this case I have no idea how to do it with music, vibration and language. Someone please guide me on this topic or share some code snippet.
If you look at the documentation for PlayerPrefs
- you did look, right? - you’ll see that it can load and save int
, float
and string
types.
If you need to save booleans (i.e. whether music is ON/OFF) you can simulate it by using 1 to denote TRUE and 0 for FALSE.
A language setting would depend on your implementation but don’t think of PlayerPrefs
only being used for scores.
when you change the setting for language, call
string language = "English";
PlayerPrefs.SetString("Language", language);
and any time you want to retrieve the value of language, call
language = PlayerPrefs.GetString("Language");
the “Language” string is an identifier. You can pass in anything, just make sure it’s unique.