Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by Astabeth · Oct 17, 2015 at 05:06 PM · quit

Quit Game button will not work

I am taking an online course in Unity. The game we are making uses premade scripts. I can't get my quit button to work to end the game on either level. I have a GameOver canvas with a quit button, and the text on the button points to the quit game script, and the canvas is set to interactable, and points to the end game text and the correct script. No one else seems to be having this problem, and no one has answered my help request in the class message boards, so I am turning here for help.

Edited to add: it doesn't work in either the preview or after I build it.

I don't know how to do code - we learn how to use it next lesson. Basically, we were told to select a prewritten code from the provided scripts folder. I did see some answers to similar problems, but I haven't yet learned what to do with the provided pieces of code.

alt text

alt text

It wouldn't let me upload another picture to show the code, so I cut and pasted it (but I don't think that's the problem):

using UnityEngine; using System.Collections;

public class UIButtonQuitGame : MonoBehaviour {

 public void quitGame()
 {
     //Closes the game
     Application.Quit();
 }

}

screen-shot-2015-10-16-at-90617-am.png (60.9 kB)
screen-shot-2015-10-16-at-90553-am.png (68.2 kB)
Comment
Add comment · Show 2
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 Astabeth · Oct 17, 2015 at 05:28 PM 0
Share

I edited the above post to reflect that the quit button doesn't work in the build, either. I had originally forgotten to mention that.

avatar image FilmmakerSteve · Feb 11, 2017 at 09:33 PM 0
Share

I am having the same issues. I actually have code working to quit the game from a menu, but once into my main game I cannot seem to get application.quit(); to work.

Sometimes I can get it to work by clicking on it repeatedly, but not all the time.

I have even tried putting a bool variable on a click event, and then having an if statement in Update that if the bool is true, then it quits the game. This doesn't work either. :(

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by yafo_unity · Aug 30, 2016 at 09:04 AM

void QuitGame() { #if UNITY_EDITOR if (Application.isEditor) UnityEditor.EditorApplication.isPlaying = false; #endif Application.Quit(); print("退出游戏"); }

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 Chasbas_80 · Feb 28, 2017 at 06:51 PM 0
Share

@yafo_unity, thanks for the code, this helps quite a bit!

avatar image
0

Answer by Jessespike · Oct 17, 2015 at 05:12 PM

Application.Quit() won't work in the Editor. It will work in builds though. If you want to make sure that the function is indeed getting called in the Editor, you can add a Debug.Log to notify yourself.

  public void quitGame()
  {
      //Closes the game
      Debug.Log("game quitted");  // Confirmation that the function is being called.
      Application.Quit();  // This only works in builds, not in the Editor play modes.
  }


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 Astabeth · Oct 17, 2015 at 05:17 PM 0
Share

Thanks, @Jessespike, but it's not working in the builds. :-(

The button goes dark for a second to indicate that I clicked it, but nothing else happens.

I have no idea what to do with the edit to the code (we learn that next week).

avatar image Jessespike Astabeth · Oct 17, 2015 at 05:33 PM 0
Share

What you showed should work. There must be something else wrong then, but I'm unable to guess what it is.

avatar image Astabeth Jessespike · Oct 17, 2015 at 05:37 PM 0
Share

That's okay. Thank you for trying to help!

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

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

Related Questions

Return a value on the console when the application terminates 0 Answers

[HOW] Quit the game only after pressing Back button TWICE 2 Answers

Pressing windows own close button 0 Answers

Why game EXE crashes after application.quit() is called? 1 Answer

Quit alert dialog box Android 0 Answers


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