- Home /
Can PlayerPrefs for Toggle.isOn?
I wanna save my toggle.name when toggle.isOn for next scene. but on next scene it just keep 1 toggle.name only. Actually I already checked more than 4 toggles. Can somebody help me to give solutions?
Comment
Answer by GrandCash · Aug 13, 2018 at 01:27 AM
There is no PlayerPrefs.SetBool but you can use this trick.
public Toggle toggle;
private void Start()
{
bool IsOn = false;
if(PlayerPrefs.GetInt("IsOn") == 1)
{
IsOn = true;
}
else
{
IsOn = false;
}
toggle.isOn = IsOn;
}
private void Update()
{
if(toggle.isOn)
{
PlayerPrefs.SetInt("IsOn", 1);
}
else
{
PlayerPrefs.SetInt("IsOn", 0);
}
}
Hi i try ur script. But i found 2 error, “ Toggle does not contain a definition for isOn and.... “ how i fix?