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 ?
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;
}
}