- Home /
How to write If the player don't play the game for 24 hours, the game is over.
Hi. I make the virtual pet game.
And I want to make this : If the player don't play game 24 hours, the game is over.
So what should I write code?
I already made the game over scene, "gameover".
And here is my code that record the time while the player don't play the game.
private void saveTime(){
PlayerPrefs.SetString(ResumeKey, TimeUtil.GetUnixTime(System.DateTime.Now).ToString());
}
private long getResumeTime(){
var lastPlayTime = long.Parse(PlayerPrefs.GetString(ResumeKey, "-1"));
return lastPlayTime == -1 ? 0 : TimeUtil.GetUnixTime(System.DateTime.Now) - lastPlayTime;
}
void Start(){
Debug.Log(getResumeTime());
}
void OnApplicationPause(bool pauseStatus) {
if(pauseStatus){
saveTime();
} else {
Debug.Log(getResumeTime());
}
}
void OnApplicationQuit(){
saveTime();
}
Comment
Answer by knobblez · Dec 02, 2018 at 06:04 PM
Upon login I would grab the computers date & time and check it against a txt file or database. Have it resave the current time & date after the check.