W
W
WasTabon2021-04-07 12:41:06
Unity
WasTabon, 2021-04-07 12:41:06

Why is saving via PlayerPrefs not working?

public void LoadNormalScene()
{
    PlayerPrefs.SetInt("money", allVariables.money);
    PlayerPrefs.Save();
    SceneManager.LoadScene("Main");
}
public IEnumerator TimerStart()
{
    for (float i = 0; i < time; i++)
    {
        yield return new WaitForSeconds(1f);
        left = time - i;
        timerText.text = "Осталось - " + left + "Секунд";
    }
    isStopped = true;
    isStopped = false;
    panelFinish.SetActive(true);
    earned.text = works.howMuchEarn.ToString();
    Debug.Log(works.howMuchEarn);
    allVariables.money = NewMethod();
    Debug.Log(allVariables.money);
}

private int NewMethod()
{
    return allVariables.money + works.howMuchEarn;
}

private void Awake()
{
    allVariables = GameObject.Find("Main Camera").GetComponent<AllVariables>();
    if (PlayerPrefs.HasKey("money"))
    {
        allVariables.money = PlayerPrefs.GetInt("money");
    }
}


And it seems to work, if you re-enter the stage, it saves, but only every other time, the next time everything is reset
606d7e1ac0914736887612.png

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question