- Home /
Question by
SuperPig_9001 · Aug 10, 2021 at 10:21 PM ·
shop
How to fix my shop
Got no idea what happened as it was working when i got off, but now my text and credit system is not working. When I go to the shop even if I have 25 creds I cannot interact or buy the shotgun.
Here's my shopcontroller
int moneyAmount; int isShotgunSold;
public TextMeshProUGUI moneyAmountText;
public TextMeshProUGUI shotgunPrice;
public Button buyButton;
// Start is called before the first frame update
void Start()
{
moneyAmount = PlayerPrefs.GetInt("MoneyAmount");
}
// Update is called once per frame
void Update()
{
moneyAmountText.text = "Credits: " + moneyAmount.ToString();
isShotgunSold = PlayerPrefs.GetInt("IsShotgunSold");
if (moneyAmount >= 25 && isShotgunSold == 0)
buyButton.interactable = true;
else
buyButton.interactable = false;
}
public void buyShotgun()
{
moneyAmount -= 25;
PlayerPrefs.SetInt("IsShotgunSold", 1);
shotgunPrice.text = "Sold!";
buyButton.gameObject.SetActive(false);
}
public void exitShop()
{
PlayerPrefs.SetInt("MoneyAmount", moneyAmount);
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex - 2);
}
}
here is my money controller
public TextMeshProUGUI moneyText; public static int moneyAmount; int isShotgunSold; public GameObject shotgun;
// Start is called before the first frame update
void Start()
{
PlayerPrefs.DeleteAll();
moneyAmount = PlayerPrefs.GetInt("MoneyAmount");
isShotgunSold = PlayerPrefs.GetInt("IsShotgunSold");
if (isShotgunSold == 1)
shotgun.SetActive(true);
else
shotgun.SetActive(false);
}
// Update is called once per frame
void Update()
{
moneyText.text = "Credits: " + moneyAmount.ToString();
}
public void gotoShop()
{
PlayerPrefs.SetInt("MoneyAmount", moneyAmount);
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 2);
}
Comment