High-Noon Shootout: Bullet Behaviour
In this post I am covering how the bullets behave, react, and manage the game state in my game.
Today’s Objective: Show you how I manage the bullet behaviour and trigger the various on-hit effects in my 2.5D wild west shooter.
The Code:
The bullet movement speed and direction is determined by the gun controller, and passed on to each bullet when it spawns:
Update just updates and tracks the bullet lifetime:
The OnTriggerEnter unity event function handles the majority of behaviour for the bullet:
The OnTriggerExit is used just to destroy the bullet when it goes off screen, so that a player cannot shoot the enemy unless they can see them on screen.
It’s a pretty simple script…
But it handles probably the second-most important element of the game, without which, the game would not function.