input key named : KeyCode.Escape is unkown

when a try to test my game it says “input key named : KeyCode.Escape is unkown” and i don’t know why.

this is the code i used.

var GUIEnabled : boolean = false;
var autoSave : boolean = false;
var paused : boolean = false;
		
function Start() {
OnLoad();
if(autoSave == true) {
autoSaveEnable();
}
}   

function Update () {
if(Input.GetKey("KeyCode.Escape") ) {
GUIEnabled = !GUIEnabled;
}

if(Input.GetKey("KeyCode.Escape") && paused == false){
paused = true;
Time.timeScale = 0;
}

else if(Input.GetKey("KeyCode.Escape") && paused == true){
paused = false;
Time.timeScale = 1;
}

if(Input.GetKeyDown("p") && paused == false && GUIEnabled == false){
paused = true;
Time.timeScale = 0;
}

else if(Input.GetKeyDown("p") && paused == false && GUIEnabled == true) {
paused = true;
Time.timeScale = 0;
}

else if(Input.GetKeyDown("p") && paused == true && GUIEnabled == false) {
paused = false;
Time.timeScale = 1;
}

else if(Input.GetKeyDown("p") && paused == true && GUIEnabled == true) {
paused = true;
Time.timeScale = 0;
}

if(autoSave == true) {
autoSaveEnable();
}

}
     
function OnGUI () {
if(GUIEnabled) {
if (GUI.Button (Rect (Screen.width / 2,Screen.height / 2 - 40,105,20), "Save Data")) {
OnSave();
}
 
if (GUI.Button (Rect (Screen.width / 2,Screen.height / 2 - 20,105,20), "Autosave True")) {
autoSave = true;
}

if (GUI.Button (Rect (Screen.width / 2,Screen.height / 2 - 0,105,20), "Autosave False")) {
autoSave = false;
}
 
if (GUI.Button (Rect (Screen.width / 2,Screen.height / 2 - -20,105,20), "Exit")) {
GUIEnabled = !GUIEnabled;
paused = false;
Time.timeScale = 1;
}
}
}

              
function autoSaveEnable() {
for(var x = 1; x>0; x++) {
yield WaitForSeconds(1);
Debug.Log("save me");
OnSave();
}
}

// a function created to save a game
 
function OnSave(){
PlayerPrefs.SetInt("CurXp", playerStats.curXp);
PlayerPrefs.SetInt("MaxXp", playerStats.maxXp);
PlayerPrefs.SetInt("CurHp", playerStats.curHp);
PlayerPrefs.SetInt("MaxHp", playerStats.maxHp);
PlayerPrefs.SetInt("CurMana", playerStats.curMana);
PlayerPrefs.SetInt("MaxMana", playerStats.maxMana);
PlayerPrefs.SetInt("Level", playerStats.level);

}

// a function created to load a game
 
function OnLoad(){
Debug.Log("loaded");
playerStats.curXp = PlayerPrefs.GetInt("CurXp");
playerStats.maxXp = PlayerPrefs.GetInt("MaxXp");
playerStats.curHp = PlayerPrefs.GetInt("CurHp");
playerStats.maxHp = PlayerPrefs.GetInt("MaxHp");
playerStats.curMana = PlayerPrefs.GetInt("CurMana");
playerStats.maxMana = PlayerPrefs.GetInt("MaxMana");
playerStats.level = PlayerPrefs.GetInt("Level");

}

Because you’re passing it as if it’s a string.

Use:

Input.GetKey(KeyCode.Escape)

Not:

Input.GetKey("KeyCode.Escape")

Change it to Input.GetKey(KeyCode.Escape) :slight_smile: