Offline production

Hi there, i am pretty new to unity and i thought to start with i will make a 2d Clicker game for android kind of like cookie clickers but i dont have a clue how to add an offline production so you earn money when you are not on the game. I was thinking about using the OnApplicationQuit() function but i can’t test to see if it works. Here is my script:

    public void OnApplicationQuit()
    {
        StartCoroutine(Quit());
    }

    IEnumerator Quit()
    {
        onApplication = onApplication + 1;
        while (onApplication == 1)
        {
            yield return new WaitForSeconds(1);
            xp = xp + xpPerSecond;
        }
    }

i have defined all my variables btw but that was at the top of the incredibly large script.
Thank you.

Not a full answer because I’m not familiar with android app develepoment, but I can give a couple comments -

  1. I’m pretty sure Android will fully stop code from running when you close the app, so your coroutine will not be called after the app is quit. In fact (and I could be wrong here) I believe when Unity sees the application quit it will automatically close out any running coroutines.
  2. OnApplicationQuit is usually only used for cleanup purposes, the app is shutting down meaning that all Unity
  3. Usually how idle resource generation is done is that you mark a timestamp when the app quits and save it (maybe in PlayerPrefs?). Then when the app starts up you can calculate the new resource gain based off of the current timestamp - previous timestamp. Look up how to get Android time settings, you can also probably find tutorials on how to do it so that it can’t be manipulated by people modifying their time settings.