Storing game objects from raycast?

Is it possible to “store” the gameobject hit by raycast in a variable somehow? I am new to unity and the way I am using raycast right now seems a bit clunky, I have a script to pick up objects but I seem to have little control of the object being hit.

Here’s what I have right now:

    var holdingObject : boolean = false;
    
    
    function FixedUpdate () {
    
    var hit : RaycastHit;
    
    var forward = transform.TransformDirection(Vector3.forward);
    
    	
    			if(Input.GetButtonDown("Fire2")){
    	
    				Physics.Raycast(transform.position, forward, hit, 5);
    				
    							if(hit.collider != null){
    				
   if(hit.collider.gameObject.tag == "jumpableObject" && holdingObject == false){
    	
    					hit.collider.gameObject.transform.parent = transform;
    					
    					hit.collider.gameObject.rigidbody.isKinematic = true;
    					
    					
    					
    					holdingObject = true;								
    				
    			}		    					
    		}			   	
    	}   
    }

I have a feeling that it should be possible to store this transform from the raycast in a variable but I am not sure how, any help to get me on the right track would be appriciated :)!

Simply store the hit object in a GameObject variable and you can keep it forever! Also a tip: Physics.Raycast returns true if it hits something and false if it doesn’t. So you don’t have to test to see if the collider equals null. You can do it like I have in the example below:

GameObject theHitObject;
if(Physics.Raycast(transform.position, forward, hit, 5)){
    //we hit something!  store the hit object
    theHitOjbect = hit.collider.gameObject; //this is how you store it
} else {
    //we didn't hit anything
}