if raycast doesnt hit?

how would i code something if a raycast doesn't hit?

i have this code :

if (hit.distance <= 2) {
    abletostand = 0;
}

i want it to also include something like :

if (hit.distance == (no hit)
abletostand = 1;

The Physics.Raycast() function return false if there's no hit.

just use:

if (Physics.Raycast(transform.position, target.position, hit, Mathf.Infinity)){
    if (hit.distance<=2){
        abletostand=0;
    }else{
        //if hit but the distance is higher than 2
    }
}else{
    //if don't hit anything
    abletostand=1;
}

A hint: use uppercase in your var to make then more clear: ableToStand

You could simplify the distance check:

ableToStand = false;
//It always starts false.

if (!Physics.Raycast(transform.position, target.position, hit, 2)){
//Rather than cast a ray to infinity, then check how far away the target was,
//Just cast the ray 2 units to begin with.
    ableTostand = true;
}

/*or instead of declaring the variable false to begin with:
else {
    ableToStand = false;
}
*/