Hello I have big trouble making an lives system .
I need a script that give me 5 lives and when i lose a life start recharging 10 minutes even if quit the game.I`ve got only a script with 50% of the code i need and isnt even working.
Im stuck on this 3 days please someone help me make this energy system work.
using UnityEngine;
using System.Collections;
using System;
public class Life
: MonoBehaviour
{
public GUIText datee;
public int life;
public int lifenumber=5;
public int timetowait=5;
public string thesave ="whenlife5back";
private bool stuffdone;
private bool stuffdonetwo;
DateTime currentDate;
DateTime whenlostLife;
DateTime whenlife5back;
void Start()
{
stuffdonetwo = true;
life = PlayerPrefs.GetInt ("life");
long temp = Convert.ToInt64(PlayerPrefs.GetString(thesave));
whenlife5back = DateTime.FromBinary(temp);
datee.text=("whenlife5back: " + whenlife5back);
//Use the Subtract method and store the result as a timespan variable
//TimeSpan difference = currentDate.Subtract(whenlife5back);
//print("Difference: " + difference.Minutes+","+difference.Seconds);
}
void Update (){
if (System.DateTime.Now > whenlife5back) {
Debug.Log ("true");
stuffdone=false;
stuffdonetwo=true;
}
Debug.Log (whenlife5back);
if (life < lifenumber && !stuffdone) {
Debug.Log ("changedinupdate");
whenlostLife = System.DateTime.Now;
whenlife5back = whenlostLife.AddMinutes (05*lifenumber);
Debug.Log (whenlife5back);
stuffdonetwo = false;
stuffdone = true;
}
if (life == lifenumber)
stuffdone = false;
if (System.DateTime.Now > whenlife5back && life < lifenumber&&!stuffdone) {
EnergySystem.lifes++;
life++;
stuffdone = true;
}
}
void OnApplicationQuit()
{
//Savee the current system time as a string in the player prefs class
PlayerPrefs.SetString(thesave, whenlife5back.ToBinary().ToString());
PlayerPrefs.SetInt ("life", life);
print("Saving this date to prefs: " + whenlife5back);
}
}