I have the following script below set the currentDate to the current time when the user launches the app and sets the time they had when clocking it to the oldTime. Currently I’m trying to figure out how many minutes have passed Ex: 1:00PM - 2:00PM is a total of 60 minutes. I’m trying to figure out how the game Candy Crush worked with it’s life timer where you get 1+ life after every half hour, basically I’m trying to produce the same effect except with every 5 minutes. Looked around for a good amount of time and I didn’t find much that would help me.
using UnityEngine;
using System.Collections;
using System;
public class LifeTimer : MonoBehaviour {
DateTime currentDate;
DateTime oldDate;
double minutes;
void Start ()
{
currentDate = System.DateTime.Now;
long temp = Convert.ToInt64(PlayerPrefs.GetString("sysString"));
DateTime oldDate = DateTime.FromBinary(temp);
print("oldDate: " + oldDate);
TimeSpan difference = currentDate.Subtract(oldDate);
print("Difference: " + difference);
}
void OnApplicationQuit()
{
PlayerPrefs.SetString("sysString", System.DateTime.Now.ToBinary().ToString());
print("Saving this date to prefs: " + System.DateTime.Now);
}
void Update()
{
}
void OnGUI()
{
long temp = Convert.ToInt64(PlayerPrefs.GetString("sysString"));
GUI.Label(new Rect(10, 10, 300, 30), "Last Time Logged: " + DateTime.FromBinary(temp));
GUI.Label(new Rect(10, 40, 300, 30), "Current Time: " + System.DateTime.Now);
}
}