Do a game shop, get the value from the outside class, come in, when you click to buy things, the amount is reduced But when pressing play again, the same value is still
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class Shopping : MonoBehaviour
{
public static Shopping instance;
public GameObject Shop;
public int Moneys2;
public Text myMoney;
public int itemPrice;
private void Awake()
{
instance = this;
}
private void Start()
{
Moneys2 = UIManager_2.instance.Moneys2;
}
public void Update()
{
myMoney.text = "Moneys: " + Moneys2;
}
public void BuyItem()
{
if (Moneys2 >= itemPrice)
{
Moneys2 -= itemPrice ;
Debug.Log("BUY");
}
else
{
Debug.Log("No Moneys");
}
PlayerPrefs.SetInt("Money",Moneys2);
Debug.Log("MON" + PlayerPrefs.GetInt("Money"));
}
public void PressShop()
{
Shop.gameObject.SetActive(true);
}
public void Exit()
{
Shop.gameObject.SetActive(false);
}
}
