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.
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");
}
}