I'm trying to make a checkbox in Unity UI that returns a bool endless game as 'true', and 'false' if it's a timed game. I want to do this with PlayerPrefs. I understand that PP only supports int, float and strings. I created a function that true to 1.
I have a Game Manager that handles the overall state of the game, this gameobject is the only one in my game that doesn't get destroyed on load.
So far the Game Manager has a bool 'endless' that is initialized as
endless = PlayerPrefs.GetInt("Endless", 1) == 0;
in the start function.
Now I have an options menu that houses the checkbox, in this script is the following:
public void OnToggleEndless()
{
if (endLessToggle.isOn)
{
PlayerPrefs.SetInt("Endless", manager.endless ? 1 : 0);
print("Endless Button ticked");
}
else
{
PlayerPrefs.SetInt("Endless", manager.endless ? 0 : 0);
print("Endless Button unticked");
}
}
But when I hook it up, play the game and go to the options menu and tick 'Endless Game', nothing happens. I tried to put the OnToggleEndless(); method in Update, but that just gives me endless lines of the print("Endless Button ticked"); message, the PlayerPrefs aren't saved. I'm wondering if the checkbox is even hooked up properly. I cannot figure this one out!