Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 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 /
avatar image
0
Question by Deng · Dec 02, 2013 at 04:54 AM · yield waitforseconds

How to delay few seconds when I quit the application?

For some reason, I hope the application will delay 5 seconds when I quit the application. It does not means I want the application delay 5 seconds and start to quit. The things I want is delay 5 seconds when the application is quitting. But I have no idea how to do it. I use "yield return new WaitForSeconds(5);" in "OnApplicationQuit()". But it didn't happen.

Comment
Add comment · Show 3
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 Commander Quackers · Dec 02, 2013 at 05:01 AM 0
Share

Can you be more specific?

avatar image DangerPenguin · Dec 02, 2013 at 05:10 AM 0
Share

Yield is an odd thing to get used to, here's my 2 cents.

The OnApplicationQuit method is called literally RIGHT before the application exits. With the way yield works, it's allowing the function to continue which allows the program to exit immediately.

Basically don't use yield in OnApplicationQuit.

As the Commander just asked, why do you need to pause inside of OnApplicationQuit? What are you trying to do within the 5 seconds that yield would give you?

avatar image Deng · Dec 02, 2013 at 08:31 AM 0
Share

I have to do things in "OnApplicationQuit" because I have some resource need to be released. If user doesn't release the resource and quit the application. I have to do it in "OnApplicationQuit" by myself. This is the reason.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by morteza_asadpour · Dec 02, 2013 at 06:59 AM

public IEnumerator Run() { yield return new WaitForSeconds(5f); Application.Quit(); } void Start() { StartCoroutine(Run()); }

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 mynameisjun · May 08, 2018 at 02:32 AM 0
Share

worse than nothing.......

avatar image
0

Answer by anthot4 · May 08, 2018 at 08:55 AM

I don't understand why you would want this, as if the user quits your game they want it to be an instant process. But anyway you can either use @morteza_asadpour way of a coroutine or an invoke function like:

Invoke("QuitGame",5.0f); // Put this in where the user triggers exiting the game, it calls the QuitGame function in 5 seconds.

void QuitGame(){ 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

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

21 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

Related Questions

Play AudioClips from a List by using yield WaitForSeconds (C#) 1 Answer

Problem with yield 0 Answers

i need to delay an action but my code isnt working 1 Answer

yield return new WaitForSeconds not working 1 Answer

Buffering button inputs 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