Found Solution
A Little Help With Player Prefs
I always have a little difficulty understanding player prefs. I have a scenario where I need to retrieve some information stored in player prefs like this:
public static void SetStartDate()
{
UserInformation.startDate = System.DateTime.Now ; //save the start date ->
PlayerPrefs.SetString("DateInitialized", UserInformation.startDate.ToString()) ;
Debug.Log ("Setting Start Date Now");
}
Here is the UserInformation script
using UnityEngine;
using System.Collections;
public class UserInformation : MonoBehaviour {
public static string LastThingSaid01{
get; set;
}
public static string LastThingSaid02{
get; set;
}
public static System.DateTime startDate;
public static System.DateTime today;
/*public static void SetStartDate()
{
startDate = System.DateTime.Now ; //save the start date ->
PlayerPrefs.SetString("DateInitialized", startDate.ToString()) ;
print ("Setting Start Date Now");
}*/
public static string GetDaysPassed()
{
today = System.DateTime.Now ;
//days between today and start date -->
System.TimeSpan elapsed = today.Subtract(startDate) ;
double days = elapsed.TotalDays ;
return days.ToString("0") ;
}
}
Basically what I want to do is get the "Start Date" and use that in an if statement something like:
if (DaysPast == 1){
Do Something
}
But I'm not quite sure how to access that properly?? In My Load Script I have this:
using UnityEngine;
using System.Collections;
public class LoadInformation {
public static void GetStartDate()
{
UserInformation.startDate.ToString( PlayerPrefs.GetString ("DateInitialized"));
}
}
I was able to get a debug to show the start date but I'm still not certain how to use that in an if statement like I mentioned earlier??
There is a great Live Training on Data Persistence from $$anonymous$$ike Geig: Live Training 3 $$anonymous$$ar 2014 - Data Persistence
Follow this Question
Related Questions
Why Does My Saved Data Not Load? 0 Answers
Bug Wtih Unity Cloud Save (Google Play Services) 0 Answers
PlayerPrefs Not Saving When I Click the Button. 1 Answer
How can I save this objects ? 0 Answers
Save coins/currency? 2 Answers