- Home /
Duplicate Question of your other question: http://answers.unity3d.com/questions/579699/attaching-two-gameobject-together.html
gameobject on gameobject
I have a bolt (for crossbows) prefab, when it hits the wall it doesn't get stuck at the wall (just goes right through it). However, when I pause after the collision, the hierarchy shows the the bolt becomes a child of the wall and its rigidbody and collider also gets destroyed. Any idea why it just passes through?
My alternate method is to destroy the bolt when it collides and replace a clone in its place. But doesn't seem to work either.
***I've attached the script to the wall. The bolt has a rigidbody and both the wall and the bolt have a collider.
void OnCollisionEnter(Collision hit)
{
//float depth = 0.3f;
if(hit.gameObject.tag == "Bolt")
{
//method 1
//hit.transform.Translate(depth * Vector3.forward); ////doesn't seem to work
//hit.transform.parent = transform;
//Destroy(hit.gameObject.rigidbody);
//Destroy(hit.gameObject.collider);
//method 2
hit.transform.parent = transform;
GameObject clone = Instantiate(boltPrefab, transform.position, transform.rotation) as GameObject;
Destroy(hit.gameObject);
}
}
Don't post the same question multiple times. Usually if a question doesn't get an answer, the question or your situation / setup isn't clear enough to answer the question. You should edit your other question and provide some more information and updates on your progress.
http://answers.unity3d.com/questions/579699/attaching-two-gameobject-together.html