Raycast length must be equal to the target distance

supose that an enemy raycast hit a crate, i want the raycast length to be the same as the (enemy , crate) distance…and when the raycast doesn’t hit something i want it to be equal
let say float 10; i tried but it doesnt work HELP ME PLEASE…
this is what i made

var RayHitDist:float=10;

var RayTarget:Transform;

function Update(){

var RTdistance=Vector3.Distance(RayTarget.position,Owner.position);

var RayLong=transform.TransformDirection(Vector3.forward);

var Rayhit: RaycastHit;

Debug.DrawRay(RayPos.position,RayLong*10,Color.green);

if(Physics.Raycast(RayPos.position,RayLong,Rayhit,RayHitDist))
{
RayTarget=Rayhit.transform; RayHitDist=RTdistance;

if(Rayhit.collider.gameObject.tag==“Ennemy”){AimTarget=false;}

if(Rayhit.collider.gameObject.tag==“Player”){AimTarget=true;}

}

if ( RayTarget==null ) { RayHitDist=10; }

}

Try putting RTdistance inside the if like:

if(Physics.Raycast(RayPos.position,RayLong,Rayhit,RayHitDist)){ 
RTdistance = Vector3.Distance(RayPos.position, Rayhit.collider.gameObject.transform.position);
RayHitDist=RTdistance;

}

thx you…and i tried for the null assignment…but i cant

when the ray cast doent collide i want it to be equal to 10