Creating the projectile system
Currently, the level contains a player and an enemy ship, which the player must shoot, as shown in Figure 4.1:
The player doesn't yet have any method of killing the enemy, so we'll start the chapter by implementing the last significant system missing from the game: the projectile system. Thinking carefully about how we want our weapon systems to behave, we can identify a few concepts that need development:
- The projectile spawn location: We need a way to spawn projectiles at a position relative to the player or enemy ships.
- We need the projectile itself. If you've read the previous chapters, you won't be surprised to hear that we'll create this as a prefab.
- We need a system to spawn the projectiles. This system will be slightly more complex than simply instantiating and destroying the missiles when required, for reasons that will become apparent. ...