- Home /
 
 
               Question by 
               cankirici34 · Sep 26, 2020 at 10:14 AM · 
                instantiateprefabprefabschild object  
              
 
              collision with instantiated prefabs child
Im instantiating a prefab and that prefab has childs. The childs tagged like "enemy" and when i instantiating a bullet to the childs they are not destroyed. It's working with parent prefabs but not working with childs of that prefabs. How can i solve this problem?? my code:
 private GameObject enemy;
 // Start is called before the first frame update
 void Start()
 {
     enemy = GameObject.FindGameObjectWithTag("enemy");
     
 }
 
 private void OnCollisionEnter(Collision collision)
 {
     if (collision.gameObject.tag == "enemy")
     {
         Debug.Log("touched");
         Destroy(enemy);
     }
     
 }
 
              
               Comment
              
 
               
              Answer by galatanubogdan14 · Sep 26, 2020 at 03:12 PM
The attached children from the parent have an enemy tag? Add a tag into them and also a collider to detect the collision.
yes they have a "enemy" tag and collider but still didn't work and then i just instantiating a prefabs without a child just single prefabs and added a tag like "enemy" it didn't work too. but when the bullet touched the instantiated prefabs Debug.Log("touched"); debug message works. 
Your answer