Remember Toggle Button State When Scene Return
Is it possible to have say a set of toggle button in a scene we'll call scene one and then set those toggles, got to scene 2 and then return to scene one and have those toggles be set as they were when you left scene one? I'm using the UI canvas system for buttons and toggles.
You can just save the toggles as bool in a persistent manager script and reset the new toggles to those values upon loading the new scene.
@vintar, Ah I kind of thought it might be something like that. So if I make an empty game object and put a script on it called "ToggleSettings" or something and then somehow pass my toggle settings to that with a don't destroy on it it will keep my toggle settings when I return to the scene I just left? If I'm understanding that right. What would I need to place in this script?
Yes, I would create an empty object and add a script to it, and in the awake method add the DontDestroyOnLoad(gameObject) call, lets call it ToggleSettings.cs. Then I would add a script to the canvas that has a simple method for each of you buttons. If you are familiar with dragging the script onto the "On Click" section of the button, then you are half way there. Something like :
ToggleSettings _toggleSettings;
void Start()
{
_toggleSettings = gameObject.Find("ToggleSaver").GetComponent();
}
//this will be the method to use in the On Click for the first button, add as many methods as you need for each button.
void FirstSliderValue(Slider slider)
{
_toggleSettings.First = slider.value; //_toggleSettings.First is a public bool
}
I was thinking about this again and the easier less complicated route would be to just use PlayerPrefs.
EVEN LESS complicated would be to have static variables. People often forget about the "static" that can be applied to variables and what it exactly does :D