When I load my script, time starts from zero. How do I save my game timer?
Here is my script:
public float seconds, minutes, hours;
public Text levelTimer;
public float GameTime;
// Update is called once per frame
void Update ()
{
hours = (int)(GameTime / 3600.0f);
minutes = (int)(GameTime / 60f);
seconds = (int)(GameTime % 60f);
levelTimer.text = hours.ToString("00") + ":" +
minutes.ToString("00") + ":" + seconds.ToString("00");
GameTime += Time.deltaTime;
}
public void save()
{
PlayerPrefs.SetFloat("second1",seconds);
PlayerPrefs.SetFloat("mins1",minutes);
PlayerPrefs.SetFloat("hour1",hours);
}
public void load()
{
seconds = PlayerPrefs.GetFloat("second1");
minutes = PlayerPrefs.GetFloat("mins1");
hours = PlayerPrefs.GetFloat("hour1");
}
loadandsaveat any point? \$\endgroup\$