Hey, all. I’ve run into something puzzling I can use some advice on. I have a very simple for loop in the Update method which runs based on the number of items I have in a list. In the example below, pos.Count = 3.
void Update()
{
for (int i = 1; i < pos.Count; i++)
{
print(i);
}
}
This code works fine, and prints 1 and 2 repeatedly, as you’d expect. The trouble comes in when I try to nest an If statement inside the for loop. Example below…
for (int i = 1; i < pos.Count; i++)
{
print(i);
if (Physics.Linecast(pos[i].position, pos[i++].position, mask))
{
print("collision");
}
}
This just keeps outputting 1. I’m sure it’s something obvious, but I can’t figure out for the life of me why the for loop is not iterating up. No errors thrown. Advice appreciated.