How To Fire Bullets With Different Fire Rate In Game Made With Unity Software | Simple Tutorial @AlexanderZotov
How To Fire Bullets With Different Fire Rate In Game Made With Unity Software | Simple Tutorial  @AlexanderZotov
Uploaded May 2020 | Updated September 2026, 3 weeks ago
In this video I will show you a simple way how to fire bullets with some reload time that you can tune the way you want it. In this case I can fire bullet only once per second.

I play games here - twitch.tv/zzotoff
You are very welcome :-)

What this video is about: How To Fire Bullets With Different Fire Rate, unity fire bullets, unity fire, unity fire rate, unity fire bullets with delay, unity fire bullet, unity fire bullet 2d, unity fire bullet forward, unity fire bullet from barrel, unity fire bullet from a gun.

I start from an empty project as usual and set it up step by step. Let’s say I have a gun. Here it is. And a bullet which will be spawned and sent every time I click left mouse button. I’m going to move this bullet using physics so in this case I have to add a rigidbody 2d component to it. Like that. I set gravity scale to 0 so my bullet will not fall down. Since this bullets is going to be spawned so I need a prefab of it. I drag & drop bullet gameobject from hierarchy to project folder and prefab to create a prefab. There we go. Bullet prefab from the hierarchy can be deleted. Ok. I want to fire bullets right from the barrel. Right click on the gun and create new empty game object that will be a child of my gun. I rename it as barrel. I position it right about here. Bullets will fly from here. Now it’s time to examine the scripts which will help me to fire bullets. First lets check out simple fire script that allows me to fire bullets each time I click left mouse button. Here I have bullet variable that helps me to spawn and send a bullet. Barrel variable helps me to set a position to spawn that bullet. And bullet speed variable holds a bullet speed value. In start method I check if fire1 button is pressed which is left mouse click by default along with ctrl keyboard button. So if this button is pressed or clicked then new bullet is instantiated at barrel position with barrel rotation. After that this new bullet is sent along barrels X axis. Pretty simple. D&D this script to gun gameobject. All I have to do before I can play this game is to assign bullet and barrel gameobjects. Select gun and D&D bullet and barrel gameobjects into corresponding slots of simple fire script component. Lets check it out. Everytime I click left mouse button new bullet is spawned and sent to the right. So if I click pretty fast then I can achieve a high fire rate and spawn a lot of bullets. But what if I want to slow that fire rate down and spawn a new bullet once per second for example not matter how fast I click. In this case I need to add some code to my fire script. Here I created another one script named fire with delay. Here it is.
It looks pretty much the same but here I have a couple of new variables which are fire rate and next fire. Fire rate determines the condition how often can I spawn a new bullet. Once per second in this case. And next fire variable helps me to check if time for the next fire has come. So in Update method I check if fire button is pressed and at the same time I check if time for the next fire has come. If these conditions are met then I reset next fire veriable and spawn a new bullet just like I did in simple fire script. Pretty simple as well. D&D this script to the gun. Disable or remove simple fire script. And assign bullet and barrel game objects. Bullet prefab goes to bullet slot. Barrel gameobject goes to barrel slot. Lets see how it works. So no matter how fast I click a new bullet can be spawned only on time per second. That’s it. Hope you find anything useful in this video. Thank you for watching and see you next time.

If you like what I'm doing then you can support me through
patreon.com/alexanderzotov
or here
paypal.me/AZotov
Thank you)
How To Fire Bullets With Different Fire Rate In Game Made With Unity Software | Simple TutorialMake Simple New Year Puzzle Game For Android Mobile Platform With Unity Software | TutorialJump On Enemy Head To Stomp Squash And Trample Him. Feature For You 2D Game Made With Unity SoftwareHow To Create Bullet Hell Feature With Simple Object Pooling System In 2D Game Made With UnityTutorial How To Add Simple Digital Score Counter Into Your Unity 2D GameEnemy Walks From One Wall To Another Changing Move Direction As He Collides With Them In Unity GameSimple Clock Puzzle Game Made With Unity SoftwareHow to make a simple coins counter for your Untiy 2d game? Simple tutorial.New Guess The Movie Game Quiz Is Available On Play Market For Free | Download And Enjoy | Unity MadeUnity Tutorial How To Make Simple Puzzle Game | Stacking Rings Pyramid Educational Game For KidsUnity Tutorial How To Create Fuel Meter Feature For Simple Jetpack Clone Android GameHow To Create Simple Portal With Sprite Splitting Feature In 2D Game Made With Unity Software
Alexander Zotov |

How To Fire Bullets With Different Fire Rate In Game Made With Unity Software | Simple Tutorial

SHARE TO X SHARE TO REDDIT SHARE TO FACEBOOK WALLPAPER