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 ?