Objective: Create a method to control the odds of spawning certain enemies and balance what powerups are spawn frequently or not.
As it stands, We have a 50/50 chance of a base type enemy or a missile launching enemy being spawned. We also have the same odds of an ammo powerup spawning as well as a life up powerup spawning. We want to make the missile enemies less frequent as well as certain powerups spawn less frequently.
I’m going to use two methods to control this. For the enemy spawning we are going to create a method that will choose the odds of spawning depending on the wave the player is on.
We will call on the method when we instantiate an enemy.
Make sure to change the variable that represents the random enemy spawn, and we are good to go.
For the powerup a different way we could control what spawns frequently is to create a separate coroutine. The one we already have will be used to handle our common powerups and negative powerups while the new coroutine will handle the rare powerups.
It will work the same way as the original only with an increased wait time before spawning. This way the player doing has to survive for longer before getting a life up or whatever other powerup we deem to be overpowered, like the big laser.
This is all there is to it. If you want to be more precise you can use the first method to further control which powerup gets spawned as well. As always, never be afraid to experiment with you code and I’ll see you in the next tutorial.