- Home /
Question by
Squiggz12 · Dec 31, 2018 at 02:36 AM ·
c#playerprefssaveshopmoneysystem
Can anyone help me figure out why PlayerPrefs wont save the money value?,Can anyone help me as to why my money won't save in my game? Using PlayerPrefs
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;
public class Earn_Money : MonoBehaviour { private bool playerinZone; public int Cash =100; public Text Money_Text;
// Use this for initialization
void Start()
{
Cash = PlayerPrefs.GetInt("MoneySaved");
playerinZone = false;
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Space) && (playerinZone))
{
Cash += 40;
Money_Text.text = "Cash: " + Cash.ToString();
}
}
void MoneyUpdate()
{
Money_Text.text = "Cash: " + Cash.ToString();
}
private void OnTriggerEnter2D(Collider2D other)
{
if (other.name == "Player")
{
playerinZone = true;
}
}
private void OnTriggerExit2D(Collider2D other)
{
if (other.name == "Player")
{
playerinZone = false;
}
}
void SaveMoney()
{
PlayerPrefs.SetInt("MoneySaved", Cash);
PlayerPrefs.Save();
print(PlayerPrefs.GetInt("MoneySaved"));
}
}
In the console, I see the money value go up, and even in game view. But the value never saves for some reason!
Comment
Answer by cgraf1 · Dec 31, 2018 at 03:39 AM
It doesn't look like the SaveMoney() function is called anywhere, unless it is being called in another script
Your answer
Follow this Question
Related Questions
Save values on different objets with same script? 1 Answer
PlayerPrefs don't work 2 Answers
Adding Value to Already Saved Values 1 Answer
How to save different values with same script? 1 Answer
Drag and Drop PlayerPrefs 2 Answers