Simple question about > and < operators

Hi there, I’m trying to find a way to sort of “flip” the > and < operators in an if statement. I’ve looked through some c# documentation but I haven’t found anything so I thought I’d ask here.

Here is my current code:

if (Input.mouseScrollDelta.y < 0)
        {           
            Down();
        }
        else if (Input.mouseScrollDelta.y > 0)
        {           
            Up();
        }

So as it is right now, if I scroll down on the mouse wheel, the Down() method gets called, and if I scroll up the Up() method gets called.

What I want is to give the player the ability to flip this. So scrolling down will call Up() and scrolling up will call Down().

The only way I can figure out to do this though is the following code:

if (Input.mouseScrollDelta.y < 0)
        {
            if (flip)
            {
                Up();
            }
            else
            {
                Down();
            }
        }
        else if (Input.mouseScrollDelta.y > 0)
        {
            if (flip)
            {
                Down();
            }
            else
            {
                Up();
            }           
        }

Where flip is a bool. I just want to know if there’s a cleaner way of doing this. I feel like there should be but I’m just not sure.

float mouseDelta = Input.mouseScrollDelta.y;
if (flip) mouseDelta *= -1;
if (mouseDelta < 0)
{        
  Down();
}
else if (mouseDelta > 0)
{        
  Up();
}
3 Likes

Beautiful! Thanks a lot, I knew there should be a simple solution around multiplying the value by -1 but I just couldn’t get there haha, thanks a ton!