Increase the time in X seconds each time the score equals a multiple of 500
I have a variable that raises time for every 500 points of score.
For now I have a code that works perfectly, but I want simplify the code with just 5 or 6 lines, because this is a endless run game and I don´t want do this method with 100 if conditions.
My code is:
if (scoreNum.Equals (500)) {
this.RaiseExtendPlay (60);
extendedplay.extendedSource.Play ();
}
if (scoreNum.Equals (1000)) {
this.RaiseExtendPlay (60);
extendedplay.extendedSource.Play ();
}
if (scoreNum.Equals (1500)) {
this.RaiseExtendPlay (60);
extendedplay.extendedSource.Play ();
}
if (scoreNum.Equals (2000)) {
this.RaiseExtendPlay (60);
extendedplay.extendedSource.Play ();
}
Answer by NoseKills · Jun 15, 2017 at 03:23 PM
Basically
private int previousMultiplesOf500;
private int score;
void Update() {
int currentMultiplesOf500 = score / 500;
if ( previousMultiplesOf500 < currentMultiplesOf500 ) {
this.RaiseExtendPlay (60);
extendedplay.extendedSource.Play ();
previousMultiplesOf500 = currentMultiplesOf500;
}
}
Sorry for later answer. I was trying to solve another $$anonymous$$or bugs.
This works perfectly.
Thanks :)
In that case please use the checkmark next to my answer to accept it :)
And please don't post comments like this as "answers" since this doesn't answer the question. Ins$$anonymous$$d post comments with the "Add comment" button. I'll convert this one to a comment.
Your answer
![](https://koobas.hobune.stream/wayback/20220612124231im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Looking for a simple Score Multiplier. 1 Answer
How do I add my Timer to my Score system in C# ? 0 Answers
how can i repeat an if statment for x sec? 1 Answer
If Time > 0.25s 1 Answer