Search Unity

Store playtime

Discussion in 'Scripting' started by phoda, Nov 25, 2015.

  1. phoda

    phoda

    Joined:
    Nov 11, 2014
    Posts:
    384
    How to store real play time, when i load game to count it and stop when i close game. Its not hard but main concern for me since its android game, how to control that when player press Home button and closes application that way. he can close game like that and it would not be saved. is there some kind of function that calls save function when that happens?

    Thanks
     
  2. phoda

    phoda

    Joined:
    Nov 11, 2014
    Posts:
    384
    bump
     
  3. ng93

    ng93

    Joined:
    Aug 31, 2012
    Posts:
    40
    I've never tried this so not sure if it'll work, but you could look into MonoBehaviour.OnApplicationPause and MonoBehaviour.OnApplicationFocus.
     
    phoda likes this.
  4. phoda

    phoda

    Joined:
    Nov 11, 2014
    Posts:
    384
    on application pause is when i put application in background (when press home button or recieve call or something like that?), but what is application focus?

    So can someone confirm this or say which functions are called when home button is pressed (or any other action that puts game in background) ?