Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 /
This question was closed Oct 27, 2017 at 01:25 AM by Bunny83 for the following reason:

The question is answered, right answer was accepted

avatar image
4
Question by Jay 2 · Aug 09, 2010 at 02:29 PM · keyexitcloseexebind

how to have the escape key actualy close the game build

Hi

I feel oh so incredibly stupid to have to ask this, so please don't remind me!

I've made a little game that I want to be able to send off etc, but when I run my builds (finished non-debug exe files) when I press the escape key, nothing happens. What do I need to add to the file to have it exit on the escape key, or do anything on the escape key (so I can have it go to a menu, where pressing exit will close the game)

Thanks

Comment
Comments Locked · 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 almo · May 11, 2011 at 09:03 PM 0
Share

You need to click the checkmark to accept the answer.

3 Replies

  • Sort: 
avatar image
26
Best Answer

Answer by jashan · Aug 09, 2010 at 02:41 PM

What you need:

  • Application.Quit
  • Input.GetKeyDown
  • KeyCode.Escape

So, what you'd probably end up is a script which implements that following Update()-method (and is attached to some game object that's available all the time):

public void Update() {
    if (Input.GetKeyDown(KeyCode.Escape)) {
        Application.Quit();
    }
}

The JavaScript version of the same can be found in the documentation of Application.Quit (see above). It's using Input.GetKey instead of Input.GetKeyDown and also uses the version which takes the name of the key instead of the keycode (I guess that's kind of the JavaScript way of doing things ... put a typo in "escape" and it'll break and you'll spend hours debugging ... well, maybe you'll get a nice runtime error and debugging will only take a few moments ;-)

Comment
Comments Locked · Show 7 · 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 Jay 2 · Aug 10, 2010 at 11:55 AM 0
Share

Fantastic, worked perfectly, thanks very much!

avatar image jashan · Aug 10, 2010 at 04:05 PM 0
Share

If this is the answer you were looking for, you should use the "check"-icon which you find below the up/down arrows to vote the answer up/down. That will mark the question as "answered" which will make it disappear from the list of unanswered questions which helps keep Unity Answers a useful place (it's kind of annoying to run through all the "unanswered questions" all the time just to find out that they're actually answered properly already because the person asking the question didn't follow their duty of also marking the correct answer "correct answer").

avatar image Jocca · Sep 24, 2015 at 12:59 PM 0
Share

Nice, getting us noobs started :)

avatar image Bunny83 · Sep 24, 2015 at 01:10 PM 0
Share

Since $$anonymous$$ 2 wasn't seen for over a year (and the question is already 5 years old.....), i've accepted the answer.

avatar image Dave-Carlile Bunny83 · Sep 24, 2015 at 01:28 PM 0
Share

Internet points are always good even if they're late. ;)

avatar image Flashmangagames · Apr 11, 2016 at 05:17 PM 0
Share

Awesome! Thanks!

Show more comments
avatar image
0

Answer by tcarausu · Mar 05, 2017 at 03:25 PM

for some reason it doesn't work i have tried key/keydown/ keycode with and without " " and no succes maybe i do something wrong?

Comment
Comments Locked · 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 FabDynamic · Aug 10, 2017 at 09:17 PM 0
Share

Hey tcarausu,

I am sure you already got your answer but I think its because it doesn't apply when you are in the editor. You have to build your game and run it from an executable for this to apply.

avatar image
0

Answer by Regah · Aug 16, 2017 at 12:22 AM

i tried the same, but my game has a first person camera which when i press esc it makes my mouse visible back again taking me out of game mode, so the esc thing does not work :( do any of you have any solutions?

Comment
Comments Locked · 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

Follow this Question

Answers Answers and Comments

8 People are following this question.

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

Related Questions

Moving Forward with an Animated Spirit (So to speak) 1 Answer

how do I close unity - and release resources 0 Answers

app just closes right after i open it? 1 Answer

Android app closes with "Texture swap animator" script in it 1 Answer

Unity and WM_QUIT 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