- Home /
Int doesn't add until after I exit playmode.
In general, what happens is when a button is pressed, it spawns a new gameobject with an assigned number. The new gameobject has a button, and when their button is pressed I want their assigned number to add to the total number. This works, but the number won't add to the total until I exit playmode. (The "total number" in this case represents the total amount of money, and the gameobject's value is represented as more money to add to the total.)
//Shared Scripts
public itemManager itm;
public MoneyManager callMoney;
public int value;
void Start () {
value = callMoney.sellValue;
}
public void childQuicksell () {
callMoney.money = callMoney.money + value; //<<<----THIS IS THE ISSUE.
callMoney.sold = true;
Debug.Log ("Sold");
}
void Update () {
}
}
I've used this line of code in many other scripts before and I've never had this issue. I've tried moving that line to the update function but the number just keeps adding up infinitely, again, only after I've exited playmode. It seems like a simple fix but I've been stuck on this for days. Anyone know what's going on here?
P.S. If you don't understand my question let me know and I'll try my best to clarify.
Reply awaiting moderation.
Assu$$anonymous$$g that you are calling childQuicksell() on button press, it looks like it should work.
How are you displaying/updating the value after the calculation appears? Is "Sold" appearing in your console log?
Answer by EdwinChua · Apr 11, 2017 at 04:26 PM
Assuming that you are calling childQuicksell()
on button press, it looks like it should work.
How are you displaying/updating the value after the calculation appears? Is "Sold" appearing in your console log?
I can see the "total money" integer in my hierarchy and once I exit playmode, the money adds up to its correct value. Yes. Everything else in the function works on button press, even the money adds up correctly but not until I exit playmode. During play it stays at zero.