How to Save the Current that what load from playerprefs
I am making a shop where player can earn money by kill the enemy, i getting it to save and be update on the shop menu but when i create a function to minus the money to see if it would change,but it would not even changing keep giving me the same amount of money i save but when i create the minus function in the save script it work good but i don't it to be there, need of help Please
using UnityEngine; using System.Collections; using UnityEngine.UI;
public class MoneyManager : MonoBehaviour {
 public  int money;
 public int currMoney;
 public Text moneyText;
 public  int addmoney;
 //public Text ShopMoney;
 //public static int Money;
 Text text;
 void Start () {
     money = PlayerPrefs.GetInt("EarnM");
     currMoney = money;
     //money = 0;
     //currMoney = PlayerPrefs.GetInt("money");
     
     //moneyText = GetComponent<Text> ();
     //currMoney = PlayerPrefs.GetInt ("EarnM",0);
     //money = currMoney;
     //currMoney = PlayerPrefs.GetInt("money" + money);
 }
 // Update is called once per frame
 void Update () {
     moneyText.text = currMoney.ToString();
     //ShopMoney.text = Money.ToString ();
     //Money = money; 
     //money = PlayerPrefs.GetInt ("money");
     if (Input.GetButtonDown ("Fire2")) {
         PlayerPrefs.DeleteAll ();
     }
 }
 //public void AddMoney()
 //{
     //money += 20;
 //}
 void OnDestroy ()
 {
 
     //PlayerPrefs.SetInt ("money", currMoney);
     //PlayerPrefs.Save ();
 }
 public void Buy ()
 {
     currMoney--;
 }
}
and this is the save where i have it in a next scene just a ui setting creating some button to add money and minus money and the PlayerPrefs function
using UnityEngine; using System.Collections; using UnityEngine.SceneManagement; public class coins : MonoBehaviour {
 public int getcoin = 100;
 public  static int earnM;
 void Awake () {
 
 }
 
 // Update is called once per frame
 void Update () {
     if (Input.GetButtonDown ("Fire2")) {
         PlayerPrefs.DeleteAll ();
     }
 }
 public void AddCoin ()
 {
     earnM += getcoin;
     //OnGoal ();
 }
 void OnDestroy ()
 {
     PlayerPrefs.SetInt ("EarnM", PlayerPrefs.GetInt("EarnM")+ earnM);
     //PlayerPrefs.Save ();
     Debug.Log ("Saved");
 }
 public void LoadMainMenu()
 {
     SceneManager.LoadScene ("Main_Menu");
 }
 public void Buy ()
 {
     earnM--;
 }
}
Your answer
 
 
             Follow this Question
Related Questions
Big numbers 2 Answers
Please help how to save last index and load 1 Answer
how i save and load my coins look the script please 0 Answers
Creating a shopping cart in Unity scripts problems 0 Answers
In Game Shop System (Use and Buy Problems) Help!!!!!!!! 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                