Currently I’m using this method to check to see if a day has passed since the user has asked a certain question. My method is working fine for the shortTimePassed,
BUT is not accurate enough for the dayHasPassed,
Since it is making a comparison based on the last time the question was asked and then the current time, so if you asked the question later in the day it would not be until later that same time the next day that it would consider a day has passed which is not what I want.
Is there another way to handle the dayHasPassed, ??
This is my code snippet:
DateTime currentDate;
DateTime oldDate;
public static bool dayHasPassed = false; // "Are You A Spaceship?" One Day Passed
public static bool shortTimePassed = false; // "Are You A Spaceship?" Short Time Passed
public static bool dayHasPassedQ02 = false; // "Are We Friends?" One Day Passed
public static bool shortTimePassedQ02 = false; // "Are We Friends?" Short Time Passed
public static bool dayHasPassedQ03 = false; // "?" One Day Passed
public static bool shortTimePassedQ03 = false; // "?" Short Time Passed
void Start()
{
Q01 (); // "Are You A Spaceship?"
Q02 (); // "Are We Friends?"
}
// Q01 "Are You A Spaceship?"
public void Q01(){
//Store the current time when it starts
currentDate = System.DateTime.Now;
//Grab the old time from the player prefs as a long
long temp = Convert.ToInt64(PlayerPrefs.GetString("sysString"));
//Convert the old time from binary to a DataTime variable
DateTime oldDate = DateTime.FromBinary(temp);
print("oldDate: " + oldDate);
//Use the Subtract method and store the result as a timespan variable
TimeSpan difference = currentDate.Subtract(oldDate);
print("Difference: " + difference);
if (difference.Days == 1) {
Debug.Log ("One Day Has Passed From old Date That You Asked If I Was A Spaceship");
dayHasPassed = true;
}
// Either 0 Days Or More Than 2 Days
if (difference.Days <= 0 || difference.Days >= 2) {
dayHasPassed = false;
Debug.Log ("At Least One Day Has NOT YET Passed From old Date That You Aksed If I Was A Spaceship");
}
if (difference.Minutes <= 20){
Debug.Log ("It Hasn't Even Been 20 Minutes Since You Aksed If I Was A Spaceship");
shortTimePassed = true;
}
if (difference.Minutes >= 21){
Debug.Log ("More Than 20 Has Passed Since you Aksed If I Was A Spaceship");
shortTimePassed = false;
}
}