Key Input Problems

I’m making a main menu using GUIText. I’m trying to make it so you have to use the arrow keys to cycle through the options and press Enter on the option you choose. Thing is, I’m getting this:

I tried putting it as an Input button and changing “GetButtonDown” to “GetKey”, but it still doesn’t work. How would I change this?

var menuItem:GUIText[];
var currentMenuItem = 0;
var keyDelay = 0.25;
enum Fade {In, Out} 
var fadeTime = 4.0; 

function Start () {
	
	while(true) {
	
		if (Input.GetKey ("up")) {
		
			currentMenuItem -= 1;
			if(currentMenuItem < 0) currentMenuItem = 2;
			yield new WaitForSeconds(keyDelay);
	
		}
	
		if (Input.GetKey ("down")) {
		
			currentMenuItem += 1;
			if(currentMenuItem > 2) currentMenuItem = 0;
			yield new WaitForSeconds(keyDelay);
		
		}
		
		if(currentMenuItem == 0) menuItem[0].material.color = Color.magenta;
		if(currentMenuItem != 0) menuItem[0].material.color = Color.black;
		
		if(currentMenuItem == 1) menuItem[1].material.color = Color.magenta;
		if(currentMenuItem != 1) menuItem[1].material.color = Color.black;
		
		if(currentMenuItem == 2) menuItem[2].material.color = Color.magenta;
		if(currentMenuItem != 2) menuItem[2].material.color = Color.black;
		
		yield;
		
		if (Input.GetButtonDown ("Enter")) {
			
			switch(currentMenuItem) {
				
				case 0:
					
					FadeAudio(fadeTime, Fade.Out); 
					yield new WaitForSeconds(2.5);
					LevelLoadFade.FadeAndLoadLevel("Beginning", Color.white, 0.5);
								
				break;
				
				case 1:
				
					FadeAudio(fadeTime, Fade.Out); 
					LevelLoadFade.FadeAndLoadLevel("_Load Menu", Color.black, 0.5);
				
				break;
				
				case 2:
				
					Application.Quit();
				
				break;
			}
		}
	}	
}

function FadeAudio (timer : float, fadeType : Fade) { 
   var start = fadeType == Fade.In? 0.0 : 1.0; 
   var end = fadeType == Fade.In? 1.0 : 0.0; 
   var i = 0.0; 
   var step = 1.0/timer; 

   while (i <= 1.0) { 
      i += step * Time.deltaTime; 
      audio.volume = Mathf.Lerp(start, end, i); 
      yield; 
   } 
}

EDIT: I forgot to mention, I’m using Unity 3… It worked fine on Unity 2.

This part is the issue:

if (Input.GetButtonDown (“Enter”))

Change it to GetKey or define it in the Project settings.

I already mentioned that. It didn’t work.

Use: Input.GetKeyDown(KeyCode.Return)

Thank you Dman. That worked :slight_smile: