Getting the keyboard to work

Hey there, I am using this code in C# in Unity:

using UnityEngine;
using System.Collections;

public class OpenMenu : MonoBehaviour {

	void OnGUI(){
		if (Event.current.Equals(Event.KeyboardEvent("[enter]")))
			Application.LoadLevel("Character Menu");
			Debug.Log("Enter pressed");
		
				
	}	
}

However when I start the game it sends “Enter pressed” continually has if someone was spamming the key; even if no-one ever touched it.
Of course actually pressing Enter would then do nothing.
And when I reversed the “LoadLevel” and the “Debug” lines; same problem, but it loaded the level instead.

Anyone here masters the keyboard ?

void Update()
{
if (Input.GetKeyDown(KeyCode.Enter))
Application.LoadLevel (“Character Menu”);
}

error CS0117: UnityEngine.KeyCode' does not contain a definition for Enter’

error CS1502: The best overloaded method match for `UnityEngine.Input.GetKeyDown(string)’ has some invalid arguments

error CS1503: Argument #1' cannot convert object’ expression to type `string’

That fixed this mistake, but I’m back at square one: It keeps pressing the key on it’s own with anyone doing anything.

You didn’t open brackets on a multi line if loop. So it only checks the line just after the if but the Debug.Log is actually out of the loop so it prints your message to the console every frame. You should use the below code.

function Update(){
    if(Input.GetKeyDown(KeyCode.Return)){
        Application.LoadLevel("Character Menu");
        Debug.Log("Enter pressed");
    }
}

function isn’t valid, but void works fine.

However when I get to the next level with a similar code; the script doesn’t work at all anymore:

using UnityEngine;
using System.Collections;

public class CharacterMenu : MonoBehaviour {
void update(){
if(Input.GetKeyDown(KeyCode.Return)){
Application.LoadLevel(“Battle Screen Test”);
Debug.Log(“Enter pressed”);
}
}

void onGUI(){
	GUI.Label(new Rect(10,10,50,25), "Name:");
	GUI.Label(new Rect(60,10,50,25), "NoName");
	GUI.Label(new Rect(10,25,50,25), "Race:");
	GUI.Label(new Rect(60,25,50,25), "NoRace");
	}

}

The void onGUI worked fine before; now it doesn’t! Even if I load this level directly.

Pressing enter in this level does nothing, even if the exact same code works fine in the first level.
And I get no errors.