- Home /
Prefab's Child doesn't trigger Colission
I have DoubleBulletPrefab that has Duplicated Child attached to it.
It is like classical Arcade game when you upgrade from SingleBulletPrefab to better gun which shoots DoubleBulletPrefab (from left and right cannon at the same time)
So the Prefab is just two capsules next to each other. (Parent, Child)
The problem I have is that the child is not triggering the collision and it’s going straight through enemy.
I tried attaching the script to child as well (Which I think I shouldn’t have to because it is child of Prefab and I want it to do exactly same thing as its Parent) but when I did that It would shoot Parent without child + my previous SingleBulletPrefab.
What am I doing wrong here?
I appreciate all sugestions and help.
How exactly do your bullet scripts work? Remember that OnTrigger messages only get sent to the object with the trigger, not the parent (unless you create a collisionForwarder script which uses Send$$anonymous$$essageUpwards("OnTriggerEnter", collider);, like I do!)
Answer by msknapp · Sep 24, 2011 at 09:11 PM
There is probably not a collider component attached to the child bullet. At runtime, pause game when the bullet fires, and look in your inspector view at the child bullet. If there is no collider attached, that is why. You probably need to add some code after you instantiate the child instance, that will add a MeshCollider to it.
GameObject g = (GameObject)GameObject.Instantiate(myBulletPrefab);
if (g.collider==null)
g.AddComponent<MeshCollider>();