do while loops always running

Please use code tags .

Couple things to note:

First, a “do…while” loop always iterates at least once, because the condition isn’t checked until the end (the “while” part). Most of the time you want a “while” loop, which checks the condition at the beginning, and therefore won’t run even the first time unless the condition is true.

Second, your condition is checking a variable that isn’t changed by anything inside the loop. That means that if the condition is true, it will run forever and crash your game. Remember, the code outside the loop will not run as long as the loop continues, and therefore can’t make it stop.

Since this is all inside an Update() function, it’s already running once per frame; you only need a loop if you want something to happen multiple times per frame. In this case, you probably don’t want a loop at all! You just want an “if” check.

1 Like