raycast to determine pivot

I have a variable called pivot which is used in a rotatearound script. I want this variable to be any gameobject that is hit by a ray. Is there a way to do this?

for example...not actual code btw


if(user presses key)

Rotate object forward(player.position,hit gameobject.forward, 90,1);


Gave it a shot myself but I am currently left with an error

NullReferenceException: Object reference not set to an instance of an object

var Player : Transform;
var rotateAmount = 90;
var controller : CharacterController;
var Hit : RaycastHit;

function Start(){
}
function FixedUpdate (){    
//casts a ray from camera to point in world
var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
// If the controller is grounded and the ray hits an object; then you can Rotate walls
if ((controller.isGrounded) && (Physics.Raycast (ray, Hit, 50))) {
    canRotate =true;    
    var pivot = Hit.collider;
if(Input.GetMouseButtonDown(1))
         RotateObjectForward(Player.position,Hit.collider.gameObject.forward, 90,1);

if(Input.GetMouseButtonDown(0))
        RotateObjectForward(Player.position,Hit.collider.gameObject.forward,90,1);
}

If you click on the error in the Console window, it should take you to the line where the error occurred. My guess would be that either Player or controller aren't set to anything.

You can set them in code (e.g. during initialization, in the Start method) or you can do it in the editor, if this script is attached to an object in the scene. Select that object, then look in the Inspector pane at the component that this script implemented, to see and set it's public variables.