x


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);
more ▼

asked Dec 21 '10 at 09:03 PM

beginner 1 gravatar image

beginner 1
8 4 4 6

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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.

more ▼

answered Dec 21 '10 at 09:32 PM

Bennet gravatar image

Bennet
16

ohhh.. thank you very much =)

Dec 21 '10 at 09:45 PM beginner 1
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3419
x2584
x2172
x785

asked: Dec 21 '10 at 09:03 PM

Seen: 4070 times

Last Updated: Dec 21 '10 at 09:03 PM