Multidirectional shot for the boss in Unity
Now that we have given our player the ability to fire homing missiles in the last article it is now time to give our boss type enemy a 360 multi-directional shot.
Above you can see how the boss will fire lasers in a circle around itself. This is a simple for loop that instead of instantiating one laser firing we’re firing 18 lasers around the boss position. Let’s have a look at the code and see how I have implemented it.
I have a time that determines whether the boss enemy can fire. If the boss can fire their lasers then we enter a for loop for a cycle of 18 times and each time a laser is instantiated I change the angle by * the current i element by 20. Making sure I have 18 loops and changing the angle by 20 each time means that we fire a laser every 20 degrees around the boss. So we go from 0 to 360 around the loop.
And that’s it for creating a boss that fires lasers in a 360 circle. You can adjust the code however you like to get the same effect. You could have an array of floats that are the angles you want the lasers to fire from and change out the number of times the loop needs to happen (i < yourArray.Length) and the i*20 part with yourArray[i].
Check back next time for more game development tips in Unity.