- Home /
How to fire minigun
Okay so I have minigun that fires 6000 RPM and I want to split firerate into each frame Im using object pooling so it should spawn (2-3) bullets per frame based on firerate (6000 / 60) and then enable/disable update position etc. on each one using my own entity class
I want it to be efficient
this is my script I made
I'm not sure what the issue you are having is.. When I fire a gun I enable a bullet at the end of the gun barrel. The bullet has a script with OnEnabled() it adds velocity to the bullet, and a OnCollision() that will disable the script. You can also use OnEnable() and Ondisable() to add and remove it from your pool. I don't think you are pooling correctly because you destroy elements of your pool, you clear your pool and repopulate it. The point of using a pool is so you don't call Instantiate() and Destroy() instead you use gameobject.SetActive(true) and gameobject.SetActive(false). And you keep track of which ones are being used and which one are available using a List, array or other collection, I like to use a list or array so I can grab an object at [0] in my pool and when I'm done with it and it's added it back to the collection, it's added to the end. The whole thing works like a queue.
Your answer