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 aled96 · Apr 03, 2014 at 06:17 PM · exitescape

Exit application

Hi, i need to exit from an application if i press a key

i wrote this:

     if(Input.GetKey(KeyCode.Space))
     {
         if(pos == 0)
             Application.LoadLevel("Scene");
         else if(pos == 1)
             Application.Quit();
     }

but Application.Quit(); doesn't work, can someone help me ? thank you:)

Comment
Add comment · Show 8
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 perchik · Apr 03, 2014 at 06:20 PM 0
Share

(is pos actually set to 1 somewhere?)

avatar image roojerry · Apr 03, 2014 at 06:49 PM 3
Share

Just to check. Are you running this from the editor or webplayer? Application.Quit will not work on either.

avatar image aled96 · Apr 03, 2014 at 07:19 PM 0
Share

yes, i set pos to 1 or 0, based on the key that you pressed

avatar image roojerry · Apr 04, 2014 at 01:31 PM 2
Share

That is your problem then. Try building a standalone($$anonymous$$ac/Win) version of your game and see if the application quits like you expect it to.

avatar image roojerry · Apr 04, 2014 at 02:00 PM 1
Share

You can use UnityEditor.EditorApplication.isPlaying = false; to stop the application from running in the editor.

Show more comments

3 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by rancid1 · Apr 04, 2014 at 03:17 PM

You can change your line 6 into the following snippet and it will behave far more intuitively for developer usage. (In that it will feed a message to the developer and explain why nothing is happening.) Stuff like this doesn't exactly make sense that it's not in the base engine... But there you have it.

 if (Application.isEditor)
   Debug.Log("Attempted to quit from the Editor.")
 else if (Application.isWebPlayer)
   Debug.Log("Attempted to quit from the Web Player.")
 else
   Application.Quit();
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
avatar image
0

Answer by KittyKatKat · Apr 03, 2014 at 06:33 PM

Should be Input.GetKeyDown(KeyCode.Space)) or GetKeyUp (Depending on how you want it).

Comment
Add comment · Show 3 · 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 perchik · Apr 03, 2014 at 06:34 PM 0
Share

well... $$anonymous$$inda.

The OP's code should work, it might just try to load the level (or quit) a bunch of times. I'm not sure that just changing to keyup or keydown will actually solve the problem.

avatar image KittyKatKat · Apr 03, 2014 at 06:45 PM 0
Share

I just tested. I don't know, it seams to work for me. OP, is your class made to DontDestroyOnLoad(); ? Because if it is, it might be made into a loop of scene loading (but in the end, it should switch to the scene anyway) Another solution would be to put in the index of your scene, rather than the name of it, maybe?

avatar image aled96 · Apr 03, 2014 at 06:50 PM 0
Share

is the same in this case use getkey, getkeyup

avatar image
0

Answer by bdsaxxy · Apr 04, 2014 at 02:53 PM

when you build it should work

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

25 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 avatar image avatar image avatar image

Related Questions

input question 1 Answer

Whats causing the problem in this script? 1 Answer

when I pause the game with "escape" and unpause the mouse apears on the screen with the fps controller 1 Answer

how do i stop/exit a coroutine? 1 Answer

BCE0044: expecting ':', found '}'. Again. 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