shooting crashes game

i am no sure why but whilst playing my game after shooting a certain amount of objects the game crashes any help will be appreciated.

here is my shoot code.

Unity can only have so much information at the same time, like everything with computer. You should destroy those bullets after some time, or even better, recycle them. Instantiate only around 20 and shoot them one after the other. Once you shot the 20th, you start again with the first. Instantiate can be expensive.

To destroy the bullet after a certain amount of time, the easiest way to do that would be to have a variable in your bullet script, call it “lifetime” or something easy like that. Then make a new function called Awake() and in there, just put Destroy(gameObject,lifetime); .

It’ll look like this:

function Awake(){
Destroy(gameObject,lifetime);
}

*Don’t forget this does not go in the update function because it is a whole new function itself.