Making object found with raycast a child of the object the ray is cast from

OK, another question from me, hopefully you aren't all getting sick of them yet.

So I have an object which moves on 2d axes in relation to a marker tracked by a camera. I want to be able to use this object (called 'controller' from here on) to manipulate other objects in the background. To do this I'm using a raycast (triggers proved problematic) to detect other objects behind the one the controller. My final plan is to make it so that if an object is being found by the raycast, then on a button press that object will become a child of the controller, become unable to effect the environment (until its replaced), hopefully become transparent and then be able to be replaced elsewhere with another button press. I'm kinda new to Unity, so i'm taking it in small steps, the first of which is to make the object a child of the controller as soon as the ray finds it.

However, I don't really know how to write code that triggers the other game object - anything I write corresponds to the controller object that casts the rays in the first place. All I want to know for now is how I write script that effects the object that is being detected by the raycaster, rather than the one thats casting it, and has the script attached in the first place? Do I write it in the same script that casts the rays, a new script attached to the other gameobject or both?

Here's my current code which is attached to the controller object:

function Update () {
var fwd = transform.TransformDirection (Vector3.forward);
//Defining the travel direction of the raycast vector
var hit :  RaycastHit;
//If Raycast collides with something, hit = true?
var LayerMask = 1 << 9;
//Interacts with 1 layer - Layer 9 - Moveable

//Draws ray vector in Scene view
Debug.DrawRay(transform.position, fwd * 50, Color.green);

//if Raycast finds a collider in front of this object in layer 9, print message 1, else print message 2.
    if (Physics.Raycast (transform.position, fwd, hit, 50, LayerMask)) {
        print ("There is something in front of the object!");       
        }

        else print ("Nothing in front of the object!");
        }

P.S if something is wrong with the idea of using a raycast to do all the stuff I mentioned before, feel free to say! I don't mind being told now and saving time in the long run!

All you need is to retrieve the other object involved in the hit, and parent it. Several parts of this object are properties of RaycastHit (if you select any keyword in the script and hit F1, Unity should show the help file detailing that function or class and its properties).

So in the section where we find something in front of the object, we just need to identify it:

var otherThing = hit.transform; // assigns variable 'otherThing' to the object

Then parent that object to this one

otherThing.parent = transform;