Problem when trying to save time

Hello everyone!

I’m made a simple runtime timer for my camera. Now I’m trying to save the time, but it doesn’t save…
Can someone give me some advice on what am I doing wrong here?

Any tip / advice is highly appreciated! Thank you very much! :slight_smile:

P.S. Sorry if my english is bad.

#pragma strict

static var timer : float;
var timer_text : GameObject;

private var check : boolean = false;

function Awake () 
	timer = PlayerPrefs.GetFloat("RecordingTime_timer");

function Update () 
		var t : System.TimeSpan = System.TimeSpan.FromSeconds(timer);
		timer_text.guiText.text = String.Format("{0:D2}:{1:D2}:{2:D2}:{3:D2}", t.Hours, t.Minutes, t.Seconds, t.Milliseconds);
		timer += Time.deltaTime;
		if(timer > PlayerPrefs.GetFloat("RecordingTime_timer"))
		PlayerPrefs.SetFloat("RecordingTime_timer", timer);

function wait ()
	check = true;
	yield WaitForSeconds(0.3);
	check = false;

You will never save the timer because your timer is always more than the saved time.

Your logic:

begin with:

timer = saved time

… then

timer += deltatime

… and

if timer < saved time, then saved time = timer