if(x > 0){ if(x<=2){}else{Won't Ever Get Here}}

(2d game)

I’m trying to manipulate the sprite animation script on a CharacterController via a Vector3 that I’m using for its velocity. The velocity.x varies from -4 to 4 (which I’ve verified via print(velocity.x) in the console).

To handle animations, I’ve set up some simple if/else statements, but if we are moving (velocity.x > 0 || velocity.x < 0), it won’t get to the else of the statement.

I’m relatively new to C# and Unity, so any help would be super-appreciated. Here’s the code:

    //Handle Idle Animations                                                                        
    if (velocity.x == 0)                                                    
    {
        if (moveDirection == 1)                                             
        {
            aniPlay.CreateSprites(16, 16, 0, 0, 16, 12);           //Works         
        }
        else                                                                
        {
            aniPlay.CreateSprites(16, 16, 0, 1, 16, 12);           //Works
        }
    }
    else
    //Handle Moving Animations
    if (velocity.x > 0)
    {
        if (velocity.x <= 2)
        {
            aniPlay.CreateSprites(16, 16, 0, 2, 10, 12);          //Always plays this when moving right
        }
        else if(velocity.x > 2)
        {
            print("I got here");                                  //Never prints
            aniPlay.CreateSprites(16, 16, 0, 6, 16, 12);          //Never plays this
        }
    }
    else
    if(velocity.x < 0)
    {
        if (velocity.x >= -2)
        {
            aniPlay.CreateSprites(16, 16, 0, 3, 10, 12);          //Always plays this when moving left
        }
        else
        {
            aniPlay.CreateSprites(16, 16, 0, 7, 16, 12);          //Never plays this
        }
    }

Actually, I figured this one out before it made it through the moderators. I was checking the value of velocity.x at the end of my Update() function, but I had this code above other code that modified the values past 1 and -1 (up to 4 and -4). Long story short, I moved the code and everything worked fine.

Thanks for the reply, though i don’t see what is different (since it should be handling the comment and line break as any other blank space?).