- Home /
Question by
oinkoinkflapflap · May 30, 2011 at 11:50 AM ·
updateif-statementsifnumbervar
only updating number vars once
when i have a variable reaching a certain number using an if statement, when it does it adds onto another number var (RoundNo += 1;) but it updates every frame the need( if(Spawned == SpawnRoundTotal){ ) is met, how can i make it only update the first frame where the need is met instead of every frame
thanks!
Comment
Answer by Peter G · May 30, 2011 at 12:26 PM
Use a boolean:
var roundNum : int;
var roundAdded : Boolean = false;
function Update () {
if(Spawned == SpawnRoundTotal) {
//you made this conditional.
if(!roundAdded) {
//Check to see if the Boolean is false.
roundNum++;
//If it is, add 1 and switch the value of the bool so that it is true.
roundAdded = true;
}
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612092219im_/https://answers.unity.com/themes/thub/images/avi.jpg)