- Home /
Deleting Multiple Bullets after Set Time
I am making an FPS game. To keep the game running fast, I decided to delete shot bullets after about 4 seconds. I decided to do that rather then on collision, because i was worried that the bullet would just pass through objects. I am just having trouble accessing the bullet clones. I tried attaching a delete script to the bullet prefab. It worked great, but only when I put the prefab in the project panel, not when I shot the bullet. So...what do I do. Can you point me in a certain direction? Thanks for all the help!
Answer by Kith · Jun 23, 2011 at 09:08 PM
If you attach a script like this
function Start() {
Destroy(gameObject, 4);
}
to the bullet prefab, it should delete every bullet consistently after 4 seconds.
Lol I don't know if it's genius or not, but it's a very handy technique when it comes to bullets or anything else that you'll be shooting a lot of. If that solved the problem, just go ahead and mark my answer as the correct one so it can show up as solved :-). Glad to have helped.
I don't get it, it works but you can't fire any more bullets after 4 seconds?
Hope you could help me.
@Denzillah - this would be attached to the script for each bullet. It says that each bullet will be destroyed after 4 seconds, or to put another way, each bullet will live for 4 seconds. The last parameter of Destory() is the time in the future to execute the command.