The way I expect this to work, is that the while loop will trigger this action, and if it makes it to the end with nothing happening, it should go through that same iteration again to roll a new random number to hopefully pass it's check this time, only THEN will i++ and proceed to the next iteration.
This works up until 2 of my targets have 0 health... then it starts looping infinitely and unity freezes... why? Shouldn't it just continue trying to roll "a" until "a" is a target with more than 0 health (as a side note, there are 6 targets, the infinite-looping begins after I've killed 2 of them usually...)?
void SelectFour ()
{
while (int i = 0; i < 4)
{
int a = Random.Range (0, 5);
if (targetHealth[a]> 0)
{
DoSomething();
i++;
}
}
}
↧