Hey Everyone!
I have been working on a money system for my game and i have a problem with one of my scripts. One of the scripts (Buying Script) grabs the ‘int’ from another script (Money Script) and subtracts it by another ‘int’.
The problem with it is that it doesn’t seem to subtract the value. Any help on this?
Buying Script:
private MoneyScript money1;
private int money2;
public int Cost;
public BuildingFollow ScriptA;
void Start()
{
money1 = GameObject.FindWithTag("MoneyCounter").GetComponent<MoneyScript>();
money2 = money1.money;
}
public void OnClick() {
if (money2 <= Cost)
{
Debug.Log("You don't have enough money");
}
else {
money2 -= Cost;
Debug.Log("RemovedMoney");
ScriptA.AddObject();
Debug.Log("AddedBUilding");
}
}
}
Money Script:
public int money;
private Text MoneyCounter;
void Start()
{
MoneyCounter = GameObject.FindWithTag("MoneyCounter").GetComponent<Text>();
InvokeRepeating("MoneyAddMinute", 0.1f, 60f);
}
void Update() {
MoneyCounter.text = money.ToString();
}
void MoneyAddMinute()
{
money += 500;
}
}