GunsAndBullets2
GunsAndBullets2 copied to clipboard
Suggestions
I actually started using GunsAndBullets1 for a project of mine, and after examining it closely, I had a few suggestions for both that class and this one (I gradually wrote my own version which differs quite substantially from this one).
- There is no need to ever call the Update() function in this class. Using coroutines makes it much easier to implement things like burst fire. Automatic fire with coroutines is a bit trickier, but ultimately coroutines are much more flexible since they are only ever triggered when the player fires.
- The use of the Queue for cycling through barrels is a bit excessive and leads to a bit of garbage collection. I actually found that this breaks on certain android builds for some reason. A simple index and modulo operation is all that is needed (ie:
Transform barrel = barrels[currentBarrelIndex];
SpawnAndFireBulletFromBarrel(barrel);
currentBarrelIndex = (currentBarrelIndex + 1) % barrels.Length;
I removed the use of queues when I did the barrel update. It's all done with indices and mod now.
I won't switch to using Coroutines though, because I think they're more trouble than they're worth.