Adding bonus points from time increasing forever.

I need a time bonus to be added to the score at the end of the level. I understand what needs to be done, just not quite how to do it.
Using this code, when I reach the end of the level it starts adding points forever, whizzing up extremely fast. I think its because its adding the remaining time but somehow still using Time.deltaTime in some way.

I seperated the code into an extra function (addUp) in an effort to move some of the code out of the Update in case that was the problem, but I must have done the wrong thing as it didnt change :frowning:

var score : int;
var timer : float = 60;

function Update()
{
timer -= Time.deltaTime;
}


//then some code to determine if the end level prerequisites have been met, if so run the addUp function (this bit is in the update too).



function addUp()
{
	var bonus = timer *2;
	score = score+bonus;
}

Update is called once every frame, so that could be anything from 30-100s times per second. You would need something in your logic to prevent reaching the code that tests if the end level pre-requisites have been met and if so exit.

In C#

private bool gameFinished = false;

void Update()
{

  if (gameFinished) return;

  timer -= Time.deltaTime;
  //all other code
  if (end level prerequisites met)
  {
     addUp();
     gameFinished = true;
  }

}