Question by
spootymilk · Jan 07, 2018 at 02:48 AM ·
ienumeratorapplication.quitonapplicationquit
application.quit() does not work in ienumerator
I would like to save some data before closing my game event if the user clic on the windows red cross to close the program.
for that purpose, i'm using this code :
void OnApplicationQuit ()
{
if (!SaveScoreMax.initdone) {
GameManager.ChoicePopup (GameManager._SaveData);
QuitWait ();
Application.CancelQuit ();
}
}
public void Quit ()
{
Application.Quit ();
}
IEnumerator QuitWait()
{
while (!SaveScoreMax.initdone) {
Debug.Log ("wait to quit");
yield return null;
}
Application.Quit ();
}
where SaveScoreMax.initdone is a bool set to false if data has changed. And the function call by the 'yes' button in the choicepopup save data and make initdone to true. i can't see the mistake....
If someone has a solution ?
Comment
Best Answer
Answer by Hellium · Jan 07, 2018 at 01:25 PM
You have to start the QuitWait
coroutine :
if (!SaveScoreMax.initdone) {
GameManager.ChoicePopup (GameManager._SaveData);
StartCoroutine( QuitWait () ) ;
Application.CancelQuit ();
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612150000im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Power up not working 0 Answers
How to use IEnumerator? Pls help! 1 Answer
while (true) loop stops when panel is set to active 0 Answers
Weird behaviour with mathf.lerp 0 Answers
Why game EXE crashes after application.quit() is called? 1 Answer