I am having trouble to update my field/variable properly. Simply my problem is: when I call AddCoins(); method, I can see on Unity that coins are increasing on the scene. However for some reason CheckPurchaseable(); can not detect the updated value of coins but works on the starting value of coins therefore "myPurchaseButtons[i].interactable = true;" never become true.
In order to manipulate any confusion in the code I wanted to use "this.coin" I am getting error of "CS0176 Static member 'member' cannot be accessed with an instance reference; qualify it with a type name instead"
why do you think , when AddCoins(); can reach the and update the values of coins where CheckPurchaseable(); cannot read the updated value of coins?
thank you
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class ShopManager : MonoBehaviour
{
public static double coins { get; set; } = 0;
public TextMeshProUGUI coinsUI;
public ShopItemScriptableObject[] shopItemSO;
public GameObject[] shopPanelsGO;
public ShopTemplate[] shopPanels;
public Button[] myPurchaseButtons;
void Start()
{
for (int i = 0; i < shopItemSO.Length; i++)
{
shopPanelsGO[i].SetActive(true);
}
LoadPanels();
CheckPurchaseable();
}
public void Update()
{
UITexts();
}
public void AddCoins()
{
coins += 20;
CheckPurchaseable();
}
public void CheckPurchaseable()
{
for (int i = 0; i < shopItemSO.Length; i++)
{
//Debug.Log("cost: " + shopItemSO[i].name + shopItemSO[i].baseCost);
if (coins >= shopItemSO[i].baseCost) // if i have enough money
{
myPurchaseButtons[i].interactable = true;
}
else
{
myPurchaseButtons[i].interactable = false;
}
}
}
public void PurchaseableItem(int buttonNo)
{
if (coins >= shopItemSO[buttonNo].baseCost)
{
coins -= shopItemSO[buttonNo].baseCost;
CheckPurchaseable();
}
}
public void LoadPanels()
{
for (int i = 0; i < shopItemSO.Length; i++)
{
shopPanels[i].titleText.text = shopItemSO[i].title;
shopPanels[i].descriptionText.text= shopItemSO[i].description;
shopPanels[i].costText.text = "Coins: " + shopItemSO[i].baseCost.ToString();
}
}
public void UITexts()
{
coinsUI.text = "Coins: " + coins.ToString();
}
}