Search code examples
c#unity-game-enginegame-enginegame-development

Possible Mistaken Empty Statement C#


Here's my code. I have counterpart set to 20 and I get the warning possible mistake empty statement with these lines. My goal is to increase speed to make it harder as you go. The same problem happens when I just enter the number 20. As of now it just adds .75 each time.

if(speed < counterpart);
            {
                speed += 0.25F;
            }
            if(speed > counterpart);
            {
                 speed += 0.5F;
            }

Solution

  • Remove those semicolons from the end of your if statements.

    Because of them, you're always running both statements in the curly braces. Your code is equivalent to this:

    if(speed < counterpart);  // empty 'if' statement, doing nothing even if true
    
    speed += 0.25F;
    
    if(speed > counterpart);  // same here
    
    speed += 0.5F;