- Home /
How Can I save my values with Toggles in UI canvas 4.6 through scenes?
Hello community.
I want to save my values of Toggles when they're true or false. But there's no PlayerPrefs.GetBool, soo how can I do it to save it through scenes when it's set on the option scene?
I've searched around but I haven't discovered the right method.
I'm using differents functions to manage Toggles.
Right now I've two. One for enable/disable keyboard and other for accelerometer.
void update()
{
OptionKeyboard()
OptionAccelerometer()
}
public void OptionKeyboard()
{
// Keyboard movement, etc
}
public void OptionAccelerometer()
{
// Accelerometer movement, etc
}
Those two functions checks if "Toggle.isOn = true or false"
How can I store it through scenes?
Thanks for the help.
Regards.
Answer by applemaniac · May 26, 2015 at 10:59 AM
You can use PlayerPrefs.SetInt and set 1 for true and 0 for false for example.
Answer by VaderCmp · Jun 05, 2016 at 04:12 PM
https://www.youtube.com/watch?v=ShmJOTg_8Ck
The video is not in english, but the code from 24:29 is working. I know is late, but maybe it's going to help somebody
Answer by vk007 · May 26, 2015 at 03:53 AM
You can either use static variables or assign it to playerprefs. Player prefs are also saved after the game is closed, so that is advantageous.
Yes, but PlayerPrefs doesn't have a .GetBool or similar to work directly with booleans, that's the problema I have and working with static variables doesn't sabe anything when game is close, like you said. And if I work with static variables the code inside brokes, because there are methods that aren't static.