If transform.position.y is greater than 5, then it is ALSO greater than -4 (since 5 > -4 and greater-than is transitive). This means it will enter your first condition EVERY TIME.

Since in your first IF you set passed to TRUE, it therefore will not enter the second IF, which requires passed to be FALSE.

I suspect you may mean <= -4 instead of >= , but if not, you should probably flip their order:

In this case, numbers larger than 5 will enter that conditional FIRST, and therefore set passed there instead of the other, more general case. You could also make it slightly easier to understand if you used an ELSE condition.

EDIT:

OK, I think I understand your goal a little better now. You want to write each condition exactly once, on the frame where they pass the y-position given. There are a couple of reasons your original code didn’t work; not resetting the boolean “passed” was a big one.