Need code help from smart people

Hi my code is meant to activate a different guis for a pause menu but its not working

#pragma strict
static var top = true;
static var middle = false;
static var bottom = false;

function Update(){
if (top && Input.GetKeyDown (KeyCode.DownArrow))
{
top = false;
middle = true;
}
if (middle && Input.GetKeyDown (KeyCode.DownArrow))
{
middle = false;
bottom = true;
}
if (bottom && Input.GetKeyDown (KeyCode.DownArrow))
{
bottom = false;
top = true;
}
if (top && Input.GetKeyDown (KeyCode.UpArrow))
{
top = false;
bottom = true;
}
if (middle && Input.GetKeyDown (KeyCode.UpArrow))
{
middle = false;
top = true;
}
if (bottom && Input.GetKeyDown (KeyCode.UpArrow))
{
bottom = false;
middle = true;
}
}

the top to middle only works when i press up and the middle to top works with both up and down and nothing else works

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;
	}
}