why does my script work on pc but not android phone

i made this simple script but it only works on pc and not android phone anyone know why ??

	private var systime:int=0;
private var tosubtract:int=0;

function OnApplicationFocus() {
//save the system time in playerpref "systime"
systime =PlayerPrefs.GetInt("systime");
PlayerPrefs.SetInt("systime", System.DateTime.Now.Hour);

//subtract new time from old time and subtract it from the player health
	var newtime:int =System.DateTime.Now.Hour-systime;
		if(newtime>0){
				 tosubtract=newtime*4;
				//print(tosubtract);
				 Pet.healths-=tosubtract;
				 tosubtract=0;
				 }
		if(newtime<0)
		{
				 tosubtract=newtime*4*-1;
				//print(tosubtract);
				 Player.healths-=tosubtract;
				 tosubtract=0;
		}
}

You could use Time.time instead. It starts to 0 when the application starts, and goes on. With your script, that would work the same way, but does not rely on system time. If using seconds is not enough, try using the other variables of the Time class (frameCount ?)

You’ve got it a bit backwards really, try this:

private var tosubtract:int=0;

function OnApplicationPause() {
 //when pused it saves the system time in "systime".
     PlayerPrefs.SetInt("systime", System.DateTime.Now.Hour);

}

 function OnApplicationFocus() {
   //when turned on it subtracts the old time from
   //   the new time subtracts it from the player.
 var newtime=System.DateTime.Now.Hour-PlayerPrefs.GetInt("systime");

    tosubtract=newtime*4;
    print(tosubtract);
    player.healths-=tosubtract;


  }

Or you could use the systime variable - but this would also support the app being closed I think.

I had that issue, I was calling SaveGame() inside OnApplicationPause(true). My SaveGame function would save all the variables using PlayerPrefs.
On my computer all was fine. The problem was that on Android, OnApplicationPause was called immediately after loading the app, so it was saving an empty game (overwriting my saved data). Try adding Debug.Log comments inside OnApplicationPause and debugging with adb logcat -s Unity