- Home /
Call A Function At A Certain Time
So, I will call the function once when the score is the multiple of 500. However, I'm stuck because I could call the function once at 500, but then it would be stuck at 1000 and the values wouldn't change.
void Update ()
{
if (ScoreManager.score % 500 == 0 && ScoreManager.score > 0 && increaseLevel == true)
IncreaseLevel (ScoreManager.score);
}
void IncreaseLevel (int score)
{
if (speed > 0)
speed = speed + 5;
else if (speed < 0)
speed = speed - 5;
if (dropAppleSeconds <= 0.05f)
dropAppleSeconds = 0.01f;
else
dropAppleSeconds = dropAppleSeconds - 0.05f;
if (score % 1000 == 0)
changeDirectionRate = changeDirectionRate + 0.05f;
increaseLevel = false;
}
Comment
Best Answer
Answer by tanoshimi · Nov 18, 2014 at 12:59 PM
How about:
private int scoreAtWhichLevelLastIncreased = 0;
Update() {
if (ScoreManager.score % 500 == 0 && ScoreManager.score > scoreAtWhichLevelLastIncreased) {
IncreaseLevel (ScoreManager.score);
}
}
void IncreaseLevel(int score) {
// Do stuff
scoreAtWhichLevelLastIncreased = score;
}
Your answer
Follow this Question
Related Questions
Run function once, is this method appropriate? 2 Answers
Calling a method once in update 1 Answer
Calling a function only once in Update 6 Answers
Update increment error (2 + 1 = 0?) 1 Answer
How do i delay function Update 3 Answers