- Home /
Destroy bullet on random collision
I'm quite new to scripting. How would I go about this? I want my bullet do be destroyed at any collision so not a specific collision.
Answer by FLASHDENMARK · Apr 03, 2012 at 06:45 PM
You'll have to use
Destroy(gameObject);
when your bullet hits a object. I am guessing that the bullet is a rigidbody so using OnCollisionEnter would not be a bad idea. Your code might look something like this:
function OnCollisionEnter(){
Destroy(gameObject);
}
Answer by fuego_see_money · Jun 19, 2015 at 08:02 PM
Hey there!
In unity, there are built-in methods that you can call from within your script. Make a new c# script called "Bullet".
in Bullet, add this below the Update function
void OnCollisionEnter(Collision c)
{
GameObject.Destroy(this.gameObject);
}
however, in order for this to actually work, you must make sure that:
a) Your bullet object has a rigidbody and a collider attached to it
b) All the moving objects you want your bullet to collide with also have both rigidbodies and colliders
c) All the static objects(not moving, such as buildings, mountains, etc) have colliders attatched to them.
Hope this helps!
Your answer
Follow this Question
Related Questions
Destroy Bullet on Random Collision 0 Answers
Destroy Turret with machine Gun 0 Answers
shoot bullet at any direction(random) 0 Answers
Destroy Bullet On Collision? 1 Answer
Object destroys on collision script 2 Answers