Parenting Object With Triggers?

How can I make an object become a child of another object upon entering a trigger and detach upon exiting?

EDIT : I figured out how to do this and I am going to leave my working script for others to use :wink:

It should “hook” the corner object and turn around the corner. I have created a script for this but I’m not too sure where to attach it or whether to identify the trigger or the rotating (Parent) object.

Here’s my script: [FIXED]

var rotator : Transform;
var player : Transform; 
 
function OnTriggerEnter(collider : Collider){
    if(collider.tag == "Trig"){
		print("Parented");
 		player.transform.parent = rotator.transform; 
    }
}
 
function OnTriggerExit(collider : Collider){
    if(collider.tag == "Trig"){
		print("Un-Parented");	   
		player.transform.parent = null;          
    }
}

just a little fix to your code you don’t really need to save the player separately cause you get it in the trigger function anyway:

var rotator : Transform;
 
function OnTriggerEnter(collider : Collider){
    if(collider.tag == "Trig"){
       print("Parented");
      collider.transform.parent = rotator.transform; 
    }
}
 
function OnTriggerExit(collider : Collider){
    if(collider.tag == "Trig"){
       print("Un-Parented");    
       collider.transform.parent = null;          
    }
}