Hello, I have been using this Save and Load system for everything else in my game but it apparently doesn’t work for these few float variables in my script. I’ll provide the code below.
public class BuyGenerator : MonoBehaviour {
public float acceleratorSwitch;
public float buttonSwitch;
public float count = 0;
void Start()
{
Load ();
}
void Update()
{
Save ();
if (count == 1)
{
purchase.gameObject.SetActive(false);
researchScript.progressBar.gameObject.SetActive(true);
researchScript.researchText.gameObject.SetActive(true);
acceleratorSwitch = 1;
buttonSwitch = 1;
}
if (count == 0)
{
purchase.gameObject.SetActive(true);
researchScript.progressBar.gameObject.SetActive(false);
researchScript.researchText.gameObject.SetActive(false);
acceleratorSwitch = 0;
buttonSwitch = 0;
}
}
public void Purchase()
{
if (populationScript.population >= 100)
{
populationScript.population = populationScript.population - 100;
timelinePopulation.afterUpgrades += 100;
totalPopulation.afterUpgrades += 100;
purchase.gameObject.SetActive (false);
count = 1;
acceleratorSwitch = 1;
buttonSwitch = 1;
}
}
private void Save()
{
PlayerPrefs.SetFloat ("GeneratorCount11", count);
PlayerPrefs.SetFloat ("AcceleratorSwitch2", acceleratorSwitch);
PlayerPrefs.SetFloat ("ButtonSwitch2", buttonSwitch);
}
private void Load()
{
count = PlayerPrefs.GetFloat ("GeneratorCount11");
acceleratorSwitch = PlayerPrefs.GetFloat ("AcceleratorSwitch2");
buttonSwitch = PlayerPrefs.GetFloat ("ButtonSwitch2");
}
}
So what this script is doing is basically if we press the purchase button and it meets the requierment, it would set “count” to 1 and it would toggle the object. The problem is after I leave and come back, the count is reset to 0 even though it was suposed to be saved to set to 1. Anyone got any ideas? Thanks.