Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Question Problem with increasing difficulty system

Discussion in 'Scripting' started by Megulan, May 10, 2024.

  1. Megulan

    Megulan

    Joined:
    Aug 17, 2021
    Posts:
    17
    So I have been trying to make difficulty increase in my game by making enemy spawning cooldown decrease with waves something like this "currentcooldown = cooldown - wave / 15" in update, it worked but I wanted to make so if cooldown would decrease under 2 it would start decreasing slower and thats where I got stuck..

    I tried to make it so cooldown would decrease to 2 so it wouldn't just jump when waves are getting divided by a larger number but then it would just hop from 2 to 1 at the moment new wave came.. this is how I tried to do it:


    "
    if(colShow >= 2)
    {
    colShow = cooldown - GameSystem.stats.waveCount / 15f;
    Debug.Log(cooldown - GameSystem.stats.waveCount / 15f);
    }
    else if(colShow >= 1.2f)
    {
    cooldown = 2f;
    colShow = cooldown - GameSystem.stats.waveCount / 35f;
    }

    if (colShow < 0.45f)
    {
    colShow = 0.45f;
    }
    "
    so I have no idea on how to fix it.
     
  2. tleylan

    tleylan

    Joined:
    Jun 17, 2020
    Posts:
    692
    Let me suggest that you don't think of it (for the moment) as a cooldown value or any other "thing" but just your need for a decreasing (or increasing) value based upon some criteria. If you think of it that way you figure out you need a GetCooldown() method (or something like it). Have it return a value of 1f for now. And you need some small test method TestCooldown() that calls it and logs the value. Then you modify the code in GetCooldown until you see values in the range you are looking for. Only then do you merge this into your game code.

    Clearly returning 1f won't work and it depends upon some conditions so you add them as parameters to the GetCooldown method and adjust the algorithm as needed. A problem people often run into is trying adjust algorithms while coding in the game. They have to watch to see what effect their change has "in the game" when you really just want to know the numbers return in the pattern you want. Isolate that code until it works.

    I for instance can't tell what colShow or cooldown or waveCount is or where they come from and we should care, pass the values in if they are needed don't rely on them existing and being visible.