Using raycasting to detect walls?

I have an object moving around, with a large sphere collider, that if the first person controller triggers, the player is locked down and the object moves toward it. I’d like to do a ray cast first to find out if it is the correct collider or not, as there will be a spherical collider on the player and the walls will have box colliders, this snippet of code has not worked, how can I do this correctly?

  var characterPos : Vector3; 
    		var sensorPos : Vector3;
    		var journeyLength : float;
    		
    		characterPos = GameObject.Find("FirstPersonController").transform.position;
    		sensorPos = GameObject.Find("Cube").transform.position;
    		
    		var hit : RaycastHit;
    		if (Physics.Raycast (transform.position, sensorPos, hit)) {
    			if(hit.collider == BoxCollider)
    			{
    				Debug.Log("WOOT")
}

I think you should pass to Physics.Raycast a parameter with the direction of the ray. This function has several overloads, the one that works for me is:

    Vector3 myPosition = myObjectTransformComponent.position;
    Vector3 rayDirection = myObjectTransformComponent.forward;    
    int rayLengthMeters=3;
    RaycastHit hitInfo;

    if(Physics.Raycast(myPosition,rayDirection, out hitInfo, rayLengthMeters)) {
    	if(hit.collider.gameObject.tag=="targetObject"){
    		Debug.Log('hit');
    	}
    }

Hope this helps