I have a options menu on 1 scene but when you load into the game (Switch scene) then come back (Switch scene) it loses all the settings. I was trying to do it with DontDestroyOnLoad and could not get it to work an i could not figure out how to read and write a text file. What is the best way to keep all the settings? Image: Here
In Unity, you can save and load settings via the PlayerPrefs class. This is a static class which means you can access settings anywhere in your Unity script files.
Example usage:
// Set the player name preference
PlayerPrefs.SetString("player_name", "Darian Benam");
// Save all the preferences
PlayerPrefs.Save();
// Load the player name from the preferences
string playerName = PlayerPrefs.GetString("player_name"); // According to this example, the value of the string will be "Darian Benam"
Reloading the settings in the menu scene will need to be done in the Start()
method of your script. You will just need to set the values of your GUI components to the return value of the getter methods in the PlayerPrefs
class.