I have a game that refills energy after one hour. i managed to make the energy fills every hour by storing the Datatime.Now
into a PlayerPrefs.SetString()
and retriving it later on as a long
. What i’m tying to do now is to show the remaining time till the next refill on a text by converting long to string. The problem now is that it cuts the time and the seconds counter is set to 100. how can i make it show as a normal countdown timer? or is there any better way to do this?
long temp1 = Convert.ToInt64(PlayerPrefs.GetString("Current Time"));
long temp = Convert.ToInt64(PlayerPrefs.GetString("End Time"));
long counter = (temp - temp1) / 10000000;
TimeSpan timeSpan = TimeSpan.FromSeconds(3600);
string timeText = string.Format("{0:D2}:{1:D2}", timeSpan.Minutes, timeSpan.Seconds);
countdown.text = counter.ToString(timeText);
Note that i’m a beginner. Thanks in advance.