how can i increase the difficulty of my game every 10 points? doing so every 10 points the difficulty increases continuously
if((score%10==0 && score != 0))
{
.....
}
how can i increase the difficulty of my game every 10 points? doing so every 10 points the difficulty increases continuously
if((score%10==0 && score != 0))
{
.....
}
Unclear if you’re asking how to make your game behave differently based on a “difficulty level” variable, or how to update that variable based on the current score, or both. Either way, your code snippet does not provide enough context.
For the former,there are many possible ways to do it based on the details of your particular game.
For the latter, rather than trying to detect the exact moment that score reaches some threshold, I suggest you just set difficultyLevel = (score / 10) with an integer division; this avoids a bunch of issues like “what if score jumps directly from 9 to 11 without being exactly 10?” or “what if you accidentally check twice before the score changes again?”. If there’s something that you need to do exactly once when the difficulty increases, then check whether (score / 10) is different from the last value of the difficultyLevel variable before you update it.
the problem is that when the score (for example) is equal to 10, the value of a variable must change. Must do this for a frame not when the score is always equal to 10
Store the target variable.
When the target variable is equal to score, increase difficulty.
Increment target variable.
ie.
private float targetVarible = 10f;
private float incrementAmount = 10f;
void Update(){
if(targetVarible == score){
//Increase difficulty
targetVarible = targetVarible + incrementAmount;
}
}
I might do it like this
//Provide the current score and the amount amount of points between difficulty levels (defaults to 10)
public int GetCurrentDifficulty(int currentScore, int stepSize = 10)
{
int currentDifficulty = currentScore / stepSize;
return currentDifficulty;
}
So if the score is 0-9, it should return difficulty 0. 10-19 it should return 1. A score of 1026 should return a difficulty of 102. Etc, etc. This just takes advantage of an effect of integer division where the result is stored in an integer, causing the remainder (or anything that would be after a decimal point) to be dropped.
A call to the above function should be pretty cheap, so you should be able to call it whenever needed. If you need to actually do something when the difficulty changes, just store what the difficulty was last frame somewhere and compare.