- Home /
Call SaveGame() when application loses focus?
I'm working on a mobile Incremental game like cookie clicker. I have a function called SaveGame() in my gamemanger singleton object. The SaveGame() Method works fine when called from a test button. What I need to do is Call this method whenever the application loses focus. For instance, the game needs to save if the user returns home, without hitting the android escape key, or if they leave the app via clining on a text. Basically whenever it loses focus to protect the user from closing the game before it can save.
void OnApplicationFocus(bool focusStatus)
{
if (focusStatus == false)
{
GameManager.Instance.Save();
}
}
This does not seem to be working.
Answer by Astrydax · Sep 01, 2016 at 11:24 PM
void OnApplicationFocus(bool focusStatus)
{
if (focusStatus == false)
{
GameManager.Instance.Save();
}
}
Does work, Unity 5.4 just needed a restart I suppose.
Answer by atcjavad · Aug 04, 2019 at 01:53 PM
The Best Answer is in this video: https://m.youtube.com/watch?feature=youtu.be&v=_-ssqurlR3A
Your answer
Follow this Question
Related Questions
object list not serializing 2 Answers
Serialize large array of class 0 Answers
container class save based on Cherno's example 1 Answer
How to store a variable after quit? (iOS) 4 Answers
Saving Data! PLEASE HELP 1 Answer