The money playerpref is either not found or not set or its just reset. And I've looked around forever nothing seems to have fixed it so here is the original piece
using System.Collections;
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using UnityEngine;
using UnityEngine.UI;
public class PlayerPrefsSet : MonoBehaviour {
private float Money;
public GameManager gameManager;
// Use this for initialization
void Start () {
if (PlayerPrefs.HasKey("HighScore"))
{
gameManager.HighScore = PlayerPrefs.GetInt("HighScore");
}
if (PlayerPrefs.HasKey("Money"))
{
gameManager.Money = PlayerPrefs.GetFloat("Money");
}
}
// Update is called once per frame
void OnApplicationQuit()
{
Debug.Log("Quitting");
PlayerPrefs.SetFloat("Money", gameManager.Money);
for (int i = 0; i < gameManager.boughtSprites.Count; i++)//setting boughtItems into PlayerPrefs
{
PlayerPrefs.SetString("SkinsBought" + i, gameManager.boughtSprites[i].name);
}
}
void OnApplicationFocus(bool hasFocus)
{
PlayerPrefs.SetFloat("Money", gameManager.Money);
for (int i = 0; i < gameManager.boughtSprites.Count; i++)//setting boughtItems into PlayerPrefs
{
PlayerPrefs.SetString("SkinsBought" + i, gameManager.boughtSprites[i].name);
}
}
void OnApplicationPause(bool pauseStatus)
{
PlayerPrefs.SetFloat("Money", gameManager.Money);
for (int i = 0; i < gameManager.boughtSprites.Count; i++)//setting boughtItems into PlayerPrefs
{
PlayerPrefs.SetString("SkinsBought" + i, gameManager.boughtSprites[i].name);
}
PlayerPrefs.Save();
}
}
↧