Checking number against boolean

So this works fine…

var direction.x = Input.GetAxis("Horizontal");    
if (direction.x)
    // direction is a positive value
else
    // direction is a negative value

.

But the following doesn’t validate. Is it not possible to compare a number with a bool in this manner?

var userSetting : bool;
if (direction.x == userSetting)
    // Both values are either negative or positive

.

// Edit: What I’m trying to do is check whether player is facing the correct direction to grab onto a ledge (Designer sets the ledge side manually) so player cannot grab a ledge with his back.

It’s not working because GetAxis returns a float, not a bool.

You can instead make userSettings an int (or short, or byte or what have you) and then check if it’s greater than 0 (true) or equal to 0 (false).

EDIT: Remember to NOT compare a float against an int. So in your example the if statement should be more like if(direction.x && userSettings > 0)

To check if direction.x is positive and userSetting is TRUE in the same test, just do this:

if (direction.x && userSetting)

instead that:

if (direction.x == userSetting)

, that you’ve used. That instruction couldn’t work because the domains of the two variables are different.