- Home /
how can I limit the shots in 2D shooting games?
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!
Answer by Commoble · Mar 08, 2017 at 05:22 PM
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.
Your answer
Follow this Question
Related Questions
How do I get the y coordinate of a terrain at any time? 1 Answer
Collider looses cloth 2 Answers
Move player to left and right 1 Answer
Enable image on mouse click 2 Answers
Is it possible to obtain velocity relative to rotation? 0 Answers