Make an objrct a child of an other

Hi guys , i’m trying to make an object wich is my player (who have a caracter controller attached) a parent to an other object (wich is a trigger) on collision . I’m using this code but nothing hapens when i run my application :

function OnCollisionEnter (other : Collision) {
if(other.gameObject.tag == “mask”) {
other.transform.parent = transform;
}
}

Please can somebody help me !! thnx .

Use the debugger or add debug output to determine:

  1. Whether the OnCollisionEnter() function is being called.
  2. Whether ‘other.gameObject.tag == “mask”’ is evaluating to ‘true’.

thnx for replying Jesse , I’m using the OnCollisionEnter() as an indipendent script assigned to my player but what do you mean by ‘other.gameObject.tag == “mask”’ is evaluating to ‘true’. If you mean that my object is actually tagged ‘mask’ then yes .

I think what he means is something like this:

function OnCollisionEnter (other : Collision) {
print("OnCollisionEnter triggered");
if(other.gameObject.tag == "mask") {
print("if statement is true");
other.transform.parent = transform;
}
}

Just so you can see how much of your script works.

On the problem, I think OnCollisionEnter won’t work with triggers, try OnTriggerEnter instead.

Here is a code make object child to parent:

var childTransform : Transform;
var parentTransform : Transform;
function LateUpdate() {
   childTransform.position = parentTransform.position;
}

Finally: congratulation to Tunisia for freedom …, my name Mahmoud from Egypt…
EGYPT + Tunisia is ONE

Thnx everyone for replying , it does somehow works now that i used " OnTriggerEnter" and “childTransform.position = parentTransform.position;” but i still have a problem the child object do not follow the rotation of the parent object ??!! can somebody please tell me how can i solve that !!

Special thnx Mahmoud , we have always been brothers ,and we will always Be …

add:

childTransform.rotation = parentTransform.rotation;

yeah !! it finally works , thnx a lot " ivkoni " and the solution was really simple :stuck_out_tongue: