- Home /
I have a bullet object and Enemy object i want to destroyed it when bullet hits enemy
i have Enemy object with tag Enemy i want to destroy Both when they collide both each other help me please quick
Answer by TexelBox · Jul 22, 2017 at 03:16 PM
You need to use a collision event, OnCollisionEnter() or OnTriggerEnter() depending upon how you set up the colliders (whether the colliders have isTrigger is checked or not). You could place a script on the bullet such as:
     public class MyBullet{
     
               private void OnCollisionEnter(Collision other) {
                      if (other.gameObject.CompareTag("Enemy")){
                                 Destroy(other.gameObject); // this destroys the enemy
                                 Destroy(gameObject); // this destroys the bullet
                      }
               }
 }
Your answer
 
 
             Follow this Question
Related Questions
2d bullets not working in WebGL, but works fine in Unity Editor/Play 0 Answers
The name "Destory" Does not exist in the current context 2 Answers
Help! Can't destroy my bullet object because is a rigidbody 1 Answer
destroy a non-trigger object hitting a trigger object? 1 Answer
i have some people walk around the scene but it will destroy after going away from the scene 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                