- Home /
Question by
ftdev · Jun 08, 2017 at 06:30 AM ·
movementrigidbody2dcollidersgameobjectsattachment
How can I join 2 objects when objectB enter in objectA' s collider?
In the game, objectB can move on player' s command and all the times it interacts with the other object' s collider it has to get attach to the latter. Each of the object at the moment have a rigidbody2D and a collider.
Comment
Answer by kornstar83 · Jun 08, 2017 at 09:40 AM
Setting the parent of one of the gameobjects should do it,
void OnTriggerEnter2D(Collider collider){
if (collider.tag == "objectB") {
collider.transform.parent = objectA.transform;
}
}