- Home /
Problem is not reproducible or outdated
Object B doesn't see Variable values that Object A does
In this first picture you can see that Larvae Count and Larvae Currency
each have a value of 5.
In this second picture you can see that Larvae Count and Larvae Currency
have not updated even though both objects are referencing the same script.
I am completely befuddled as to why Object A can see the values but Object B cannot. If it's a code issue then I'm equally as confused. The commented out function at the bottom may be the culprit but I also think I can do things neater instead of using two functions. If I can get object B to see the values of the variables then I can manage the rest.
And frankly, knowing my luck this will be something that I'll face palm right after finding out the answer.
public Click click;
public UnityEngine.UI.Text itemInfo;
public UnityEngine.UI.Text larvae;
public UnityEngine.UI.Text workers;
public float cost;
public int larvaeCount = 0;
public int workerCount = 0;
//public string itemName;
//private float _newCost;
public float larvaePerClick = 1;
public float larvaeCurrency = 0.00f;
public float workerPerClick = 1;
public float workerCurrency = 0.00f;
private void Update(){
//itemInfo.text = itemName + "\nCost: " + cost + " Egg";
larvae.text = "Larvae: " + larvaeCurrency;
workers.text = "Workers: " + workerCurrency;
}
public void UpgradePurchase(){
if (click.eggCurrency >= cost) {
click.eggCurrency -= cost;
larvaeCurrency += larvaePerClick;
larvaeCount += 1;
}
}
/*public void UpgradeWorker(){
if (larvaeCurrency >= cost) {
larvaeCurrency -= cost;
workerCurrency += workerPerClick;
workerCount += 1;
}
}*/
Answer by PedroAK · Jun 16, 2018 at 02:14 AM
How did it get to 5?
Both of the objects that I'm asking about are buttons. When I click Button A it increases the variables of Larvae Count and Larvae Currency, which is what I want. But as you can see from the second picture the variables do not update according to Button B, this causes Button B to not work correctly when I implement code for it to function.
If I can figure this out then I can work on making Button B work correctly.