GunsAndBullets2 icon indicating copy to clipboard operation
GunsAndBullets2 copied to clipboard

Suggestions

Open LarsDu opened this issue 4 years ago • 1 comments

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;

LarsDu avatar Feb 10 '21 07:02 LarsDu

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.

brihernandez avatar Apr 12 '21 20:04 brihernandez