Save current time when Game Over, then compare to new current time and get the difference?
Hello everyone! I'm working on this:
I have 5 actual lives of the 5 Max lives capacity (full lives). When I GameOver I store the current DateTime and Add 30 min. to auto-fill 1 life. If I lose again I'll add 30 more min. to fill another life and so.
Is like that popular mobile games system to refill lives like TwoDots or Folt.
The problem is I have troubles with my code, it is no working :/ I'm not getting the difference between the start of the counter and the actual time. This is my code:
public class myClass : MonoBehaviour {
public int Max_lives = 5;
public int Actual_lives;
DateTime time_start;
DateTime time_now;
DateTime last_time;;
void Start () {
if (!PlayerPrefs.HasKey("Actual_lives_ready"))
{
PlayerPrefs.SetInt("Actual_lives_ready", Max_lives);
}
}
void Update ()
{
time_now = DateTime.Now;
if (Actual_lives < Max_lives)
{
for (int aument = Actual_lives; aument < Max_lives; aument++)
{
time_start.AddMinutes(30);
TimeSpan diff = tiempo_now.Subtract(time_start);
if (time_now >= time_start) // Here I want to get the difference between the two times, I think I dont get it yet. if already pass 30 min after time_start then:
{
Actual lives = actual lives + 1;
}
}
}
}
public void GameOver()
{
if (Actual_lives == Max_lives)
{
tiempo_inicio = DateTime.Now;
PlayerPrefs.SetString("Hour_Start", tiempo_inicio.ToString());
}
Actual_lives = Actual_lives - 1;
}
}
Comment
Your answer
Follow this Question
Related Questions
Counting Days Using In-Game Time System? 1 Answer
Get device time type(24h or am/pm) 0 Answers
Seconds from now to seven o'clock. 1 Answer