Your logic actually looks sound, but I think what you’ve missed is that more than one of those If statements can trigger at once. For instance if you’re at Top and you press down, the first If triggers and now you’re at middle, but then the code for the second If runs as well, and you’re still set as pressing the down arrow this frame, so that code runs too. You can probably fix your version just by making all but the first If into Else If.
Here’s a less fiddly solution that works, doing basically the same thing as you, but using an enum instead of the three bools and splitting out some of the logic into separate methods:
#pragma strict
enum MenuState { Top, Middle, Bottom }
var menuState = MenuState.Top;
function Update() {
if (Input.GetKeyDown(KeyCode.DownArrow)) {
MenuDown();
}
else if (Input.GetKeyDown(KeyCode.UpArrow)) {
MenuUp();
}
}
function MenuDown() {
switch (menuState) {
case MenuState.Top:
menuState = MenuState.Middle;
break;
case MenuState.Middle:
menuState = MenuState.Bottom;
break;
default:
menuState = MenuState.Top;
break;
}
}
function MenuUp() {
switch (menuState) {
case MenuState.Top:
menuState = MenuState.Bottom;
break;
case MenuState.Middle:
menuState = MenuState.Top;
break;
default:
menuState = MenuState.Middle;
break;
}
}