- Home /
 
               Question by 
               kilfoylec · Oct 18, 2018 at 04:38 PM · 
                c#collisiongameobjectdestroyontriggerenter  
              
 
              How to only delete one of two collided objects?
I have two objects being detected through two different triggers, and when a missile collides with both at the same time I want only the first to be deleted, while the other must remain.
 if (collision.gameObject.CompareTag("TargetCross") == true || collision.gameObject.CompareTag("Cross") == true)
         {
             Destroy(/*only the object tagged with TargetCross*/);
         }
               Comment
              
 
               
              Answer by Hellium · Oct 18, 2018 at 04:43 PM
 private GameObject missile ;
 void OnCollisionEnter( Collision collision )
 {
     if (collision.gameObject.CompareTag("TargetCross") )
     {
           missile = collision.gameObject ;
     }
     if ( collision.gameObject.CompareTag("Cross") && missile != null )
     {
          Destroy( missile );
     }
 }
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                