Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by 20121996 · Jan 04, 2014 at 02:22 PM ·

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

 
 

 
 


 
     
         
   
Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image HappyMoo · Jan 04, 2014 at 02:23 PM 1
Share

Please use meaningful titles and not "why doesn't this code work?" Also format code as code by using the 101/010 button. I edited that for you.

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by tanoshimi · Jan 04, 2014 at 02:45 PM

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

Use:

 Input.GetKey(KeyCode.Escape)

Not:

 Input.GetKey("KeyCode.Escape")
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Josh707 · Jan 04, 2014 at 05:09 PM 0
Share

Get$$anonymous$$ey can be passed a string as well, though it would have to be in a different format - You wouldn't write "$$anonymous$$eyCode.X" but just "X", according to the 'button names' section on the input documentation:

docs.unity3d.com/Documentation/$$anonymous$$anual/Input.html

So it would be written as:

 Input.Get$$anonymous$$ey("escape")
avatar image
0

Answer by Giannis7312777 · Jan 04, 2014 at 06:33 PM

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

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

22 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

A node in a childnode? 1 Answer

itween move to do not end(even it is) 0 Answers

Fps Aiming Script help 2 Answers

Can I use DataTable in unity and how? 1 Answer

Stop Script Completely. Doesn't Execute Another Line Of Code. 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges