Hello all. I have an inventory of darts in my game that starts out as 50. When “round 2” begins, I want to add 50 more darts to whatever total is leftover from “round 1” for example: if I have 10 leftover from round 1, I want to have 60 to start round 2. My code now reads: if round == 2, darts.dartvalue +=50.
the problem is that it updates my inventory for like 4 seconds while “round 2” is being displayed and I end up with 5000 darts. How can I just add 50 once to my overall total? Thank you for helping!
You could check if the 50 points have been added with a boolean variable that turns to false when the 50 darts have been added. Like this:
bool readyToAddPoints = true;
if(readyToAddPoints)
{
darts.dartsvalue += 50;
readyToAddPoints = false;
}
Then whenever you have to update the darts value again, just set the bool to true.
Why not do a method called ResetRound()
that will add the darts to players?
The cleanest/easiest solution I came up with was to call the static variable via an animation event that happens only if you make it to the next round therefore calling a function that adds more darts to the player inventory. Thank you all for your help, to anyone looking at this in the future, there are some real solutions here. All the best, take care!