- Home /
 
               Question by 
               beginner 1 · Dec 21, 2010 at 09:03 PM · 
                collisiongameobjectdestroy  
              
 
              Destroy object when hit by other object
how can i determine if my object cube(tag as target) is hitted by my bullet(tag as bullet)
because i want to destroy each cube im hitting with my bullet..
i have a code place in a cube but the cube is destroyed right after it hit the floor
function OnCollisionEnter(theCollision : Collision){
if(theCollision.gameObject.tag=="bullet");
Destroy(gameObject);
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by Bennet · Dec 21, 2010 at 09:32 PM
Try this:
function OnCollisionEnter(theCollision : Collision){
   if(theCollision.gameObject.tag=="bullet") {
     Destroy(gameObject);
   }
}
You had a ; after your if. That caused a Destroy on each collision.
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                