Hi, i am currently working on a shop for my platformer, and everything works except the unlock button does not turn interactable when i have enough money. I have made a reset button that resets all playerprefs. If i have enough money and THEN press reset, everythings works perfectly. But the reset button are not meant to be in the final version. But if i press reset before i get enough money the button does not work. So i need a way to maybe refresh the scene and check if i have more money than the price of the item? Any suggestion is appriciated and if you have more questions just ask:)
Here the code:
using System.Collections;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class ObjectBuyer : MonoBehaviour
{
public static int score;
int isObjectSold;
public int objectPrice;
public Text text;
public Text ObjectPrice;
public Button buyButton;
public Button selectButton;
// Use this for initialization
void Start()
{
score = PlayerPrefs.GetInt("PlayerCurrentScore");
score = PlayerPrefs.GetInt("IsObjectSold");
}
// Update is called once per frame
void Update()
{
isObjectSold = PlayerPrefs.GetInt("IsObjectSold");
if (score >= objectPrice && isObjectSold == 0)
buyButton.interactable = true;
else
buyButton.interactable = false;
if (isObjectSold == 0)
selectButton.interactable = false;
}
public void buyObject()
{
ScoreManager.AddPoints(-objectPrice);
PlayerPrefs.SetInt("IsObjectSold", 1);
buyButton.interactable = false;
selectButton.interactable = true;
}
public void exitShop()
{
PlayerPrefs.SetInt("Score", score);
SceneManager.LoadScene("Main Menu");
}
public void resetPlayerPrefs()
{
score = PlayerPrefs.GetInt("PlayerCurrentScore");
buyButton.interactable = true;
//objectPrice.text = "Unlock";
PlayerPrefs.DeleteAll();
}
},