Deleting Bullets after a few seconds

Hi

I’m making an FPS multiplayer game. I know that alot of objects will slow down the game, and since there will be alot of shooting, I thought that it would be good to delete the bullets after about four seconds. I didn’t want to delete them after collision because I thought they might just go through the floor or other objects…

My question is how do I delete each cloned bullet four seconds after it was shot? Can you send me in a direction (a tutorial or article) or maybe post the rough out line of a script? Thanks for all the help!!!

Just do it:

void Start()
{
  Destroy(gameObject,DeathTime);
}

OR

void Start()
{
  Invoke("Kill",DeathTime); 
}
void Kill()
{
  Destroy(gameObject);
}

It is easy!

And the best is that do not Instantiate the bullet with Mesh rendere On.make Mesh rendere Off to reduse the Draw Call and use a particle for bullet trace like Bootcamp.

Regards.

Something like this is very simple, so if you intend to make a full-blown multiplayer first-person shooter, you have some serious work ahead of you.

I only say this to help, because beginners often take on projects that are far beyond the scope of their abilities right out of the gate, then they feel hopeless and quit.

As to the question at hand, you want a variable to hold some sort of timer.

public float timer;

Then in your Update function, you’ll want something to increment the timer.

timer += 1.0F * Time.deltaTime;

(1 gets added to timer per second)

Then you’ll need a conditional check to destroy the bullet.

if (timer >= 4)
{
GameObject.Destroy(gameObject);
}