Raycast Rotating Camera

I was trying to make a camera that would rotate to the right, left, front, or back of the player if the camera comes too close to an object but it's not working. Can anyone offer some insight?

    var degrees = 180;
var target : Transform;
var dist = 0.3;
function Update () {
    var hit : RaycastHit;
    var fwd = transform.TransformDirection(Vector3.forward);
    var back = transform.TransformDirection(-Vector3.forward);
    var right = transform.TransformDirection(Vector3.right);
    var left = transform.TransformDirection(-Vector3.right);

    if (Physics.Raycast (transform.position, fwd, dist)) {
        print ("There is something in front of the object!");
        Debug.DrawLine (transform.position, hit.point);
    //  transform.RotateAround (target.position, Vector3.up, degrees * Time.deltaTime);

    }
    if (Physics.Raycast (transform.position, back, dist)) {
        print ("There is something behind the object!");
        Debug.DrawLine (transform.position, hit.point);
        transform.RotateAround (target.position, Vector3.up, -degrees * Time.deltaTime);

    }
    if (Physics.Raycast (transform.position, right, dist)) {
        print ("There is something on the right of the object!");
        Debug.DrawLine (transform.position, hit.point);
        transform.RotateAround (target.position, Vector3.up, degrees * Time.deltaTime);

    }
    if (Physics.Raycast (transform.position, left, dist)) {
        print ("There is something on the left of the object!");
        Debug.DrawLine (transform.position, hit.point);
        transform.RotateAround (target.position, Vector3.up, -degrees * Time.deltaTime);

    }
}

Are you sure the radius of your character controller (I assume that's what you're using) is lesser than "dist" ? If radius = 0.5 and dist = 0.3, the ray will never reach outside of your character, thus never collide anything. And check where the transform.position is. It's likely to be at your character's feet, and you'll probably prefer the center -> renderer.bounds.center should work.

Hope that helps.

[ * EDIT * ]

It seems to work with that code. I removed the TransformDirection function for the direction variables and, less important, DrawLine second parameter is an end position, not a direction.

var degrees = 180;
var target : Transform;
var dist : float = 0.3f;

function Update () 
{
    var hit : RaycastHit;
    var fwd = transform.forward;
    var right = transform.right;
    var up = transform.up;
    var back = -fwd;
    var left = -right;
    var down = -up;

        Debug.DrawLine (transform.position, transform.position + right, Color.red);
        Debug.DrawLine (transform.position, transform.position + up, Color.green);
        Debug.DrawLine (transform.position, transform.position + fwd, Color.blue);

    if (Physics.Raycast (transform.position, fwd, dist)) {
        print ("There is something in front of the object!");
        Debug.DrawLine (transform.position, transform.position + hit.point);
    //  transform.RotateAround (target.position, Vector3.up, degrees * Time.deltaTime);

    }
    if (Physics.Raycast (transform.position, back, dist)) {
        print ("There is something behind the object!");
        Debug.DrawLine (transform.position, transform.position + hit.point);
        transform.RotateAround (target.position, Vector3.up, -degrees * Time.deltaTime);

    }
    if (Physics.Raycast (transform.position, right, dist)) {
        print ("There is something on the right of the object!");
        Debug.DrawLine (transform.position, transform.position + hit.point);
        transform.RotateAround (target.position, Vector3.up, degrees * Time.deltaTime);

    }
    if (Physics.Raycast (transform.position, left, dist)) {
        print ("There is something on the left of the object!");
        Debug.DrawLine (transform.position, transform.position + hit.point);
        transform.RotateAround (target.position, Vector3.up, -degrees * Time.deltaTime);
    }
}

What you're looking for is to avoid entering meshes, right? So why don't you simply apply a sphere collider with a desired radius to your camera so that whenever it hits an object it easily remains there or rolls over the object (since it's a sphere). I mean that can be a simple solution. Cause what if there are too many objects in your scene and raycasting can be very costly on the performance.