In 2D shooting game just like Gradius, despite the firerate,how can I limit the defalut shots in 4 shots once upon a time?(That means If there are already instantiated 4 shots in the Screen,then i can’t instantiate more shots.But once a shot has gone out of the screen and been destroyed, a new shot can be fired form my ship?)
plz teach me how to write the script and thank you!

Keep track of an “ammo” variable on your ship’s script.

Whenever you fire, subtract 1 from this variable.

Have the bullet objects keep a reference to the ship, and when the bullet is destroyed, add 1 to the ship’s ammo variable.

In the ship’s script, require that the ammo variable be greater than 0 in order to fire.