- Home /
How to destroy gun bullet clone?
ok so i have a rigged gun model and it shoots fine and the animation works fine but my bullets are spheres, i was going for more of an airsoft gun effect. but anyways how can i make it so the clones of the spheres get destroyed after so many are made, or something like that?
Answer by SirGive · May 29, 2011 at 05:17 AM
Well first you might want to destroy it after 5 seconds, right? So here is the way to do that in JS:
function Update () {
Destroy (this.gameObject, 5);
}
But you also might want to destroy it on collision, so here is how you would do that:
function OnTriggerEnter(){
Destroy (this.gameObject);
}
Just write these in an empty JS file and attach it to the object. And when you create these sphere clones, just instantiate a prefab of the sphere with this script attached.
However, do note that using actual collisions for bullets is not efficient and could cause problems on a large scale.