Call a function

Hi I have a small problem, I have a 2D level which scrolls from the right to the left, when the player reaches a specific Number of points the speed in which the level moves should be increased. My code for that is as follows

function Update ()
{

if (playerScore >= SpeedIncrease1)

	MoveLevelScript.speed += 2;

}

The Code so far works fine however, the speed does not get increased once by 2, insteand it gets constantly increased so the game is not playable anymore.
I think this might happen because of the Update function, so I guess the best way of doing it would be to call a seperate function which then handles the speed increase am I correct ? If yes how would I do that ?

Try:

function Update () {

if (playerScore >= SpeedIncrease1)

    MoveLevelScript.speed += 2;
    playerScore = 0;   
}

You are in the update, and let’s say playerScore is 10 and SpeedIncrease1 is 10 then every frame your condition is true.

Reset playerScore to 0.

How about two different variables? One that keeps track of your overall points and one variable that counts just to the next level.

Another way is to set the absolute speed with some kind of mathematical formular. For example if you want a speed increase everyy 100 points:

var StartSpeed = 20.0;
var SpeedIncrease = 3.0;

speed = StartSpeed + Mathf.Floor(playerScore / 100)*SpeedIncrease;

As result the speed goes like this:

points   speed
0-99     20
100-199  23
200-299  26
...

Make speedincrease an array and have a pointer variable that you increase every time you increase speed. I hope you understand me.
Like this:

var SpeedIncrease : int[]; //Change this in inspector
var SpeedIncreaseCount : int = 0;
function Update()
{
   if(playerScore > SpeedIncrease[SpeedIncreaseCount])
   {
        MoveLevelScript.speed += 2;
        SpeedIncreaseCount += 1;
   }
}