# How do i set conditions for an IF statement as the game progress through “difficulty”?

This is code that I wanted to put in my IF statement

``````    public GameObject fallingRockPrefab;
public Vector2 spawnsMinMax;
float randX;
float randY;

//Spawn Positions
Vector2 SpawnPosition;
float nextSpawnTime;

void Update()
{
if (Time.time > nextSpawnTime)
{
float SpawningInBetween = Mathf.Lerp(spawnsMinMax.y, spawnsMinMax.x, Difficulty.GetDifficultyPercent());
print(SpawningInBetween);
nextSpawnTime = Time.time + SpawningInBetween;

randX = Random.Range(-5.6f, 5.6f);
randY = 5.57f;
SpawnPosition = new Vector2(randX, randY);
Instantiate(fallingRockPrefab, SpawnPosition, Quaternion.identity);

}

}
``````

This is the code from my “Difficulty.GetDifficultyPercent”

``````    public static class Difficulty
{
static float secondsToMaxDifficulty = 30;

public static float GetDifficultyPercent()
{
return Mathf.Clamp01(Time.timeSinceLevelLoad / secondsToMaxDifficulty);
}
}
``````

I’m planning to make a certain event happen when my game bypass a certain stage of a difficulty as it progress but I just don’t know what to put it as.

My guess is this,

if(Time.time > Difficulty(25))

but didn’t work.

I don’t understand what’s going on in the scripts above, they don’t seem related to your difficulty-over-time question.

Generally you associate specific game metrics with varying difficulties.

For simplicity I’ll say “enemy speed.”

• Enemies start slow
• Enemies speed up periodically
• Enemies MIGHT reach an upper speed limit (or not)

That’s just one metric. You might adjust other metrics (fire rate, bullet speed, damage dealt, etc.), but let’s keep this simple.

Basically you have an `enemySpeed` variable that controls such behavior

• You reset that enemySpeed to the minimum (slow) at game start
• you start a timer
• when that timer expires, you increase the difficulty metric and reset the timer
• when the difficulty metric reaches the maximum you no longer increase it (this is optional)

Alternatively you can derive the enemySpeed in real time by some type of calculation from other variables, such as saying

``````// enemies speed up as the game moves onwards
LevelGameplayTimer += Time.deltaTime;
enemySpeed = BaseEnemySpeed + LevelGameplayTimer * EnemySpeedIncreasePerSecond;
``````

What did you expect `Difficulty(25)` to do? Did you define a function named “Difficulty” somewhere?

If you are trying to call the function from your last code snippet, the syntax for that would be `Difficulty.GetDifficultyPercent()`. You won’t want to compare that to the current time, though, because it is returning a percentage (in the range 0-1), not a time.