Day 36- Making 2D Space Shooter Game
Objective: Add a laser beam that rotates and destroys every enemy and enemy laser it touches.
To make this happen, the easiest way to do the laser is animating it to rotate in unity editor.
After creating the animation, disable the loop and add collider and rigidbody to the destructive laser.
Now place the created destructive laser inside Player gameobject.
create a script and put it inside the destructive laser. Then add the trigger when it detects object tagged Enemy_laser, it destroys that gameobject.
Make sure to set your enemy tag to Enemy_Laser or else the enemy laser will not be destroyed and player will be hurt if touched.
Add this script inside OnTriggerEnter of Enemy script to destroy the enemy whenever enemy touches the destructive laser.
Now set your condition to fire normal laser only when destructive laser is inactive.
Now create a coroutine which will wait for 5 seconds and set your destructive laser bool to false and destructive laser to inactive.
And create a public method to set your destructive laser to be active when called and call the coroutine to set the timer to 5 seconds after which it will be deactivated and normal laser can be fired.
Finally call the DestructivePowerup method whenever the player collects the destructive laser collectable. Make the spawn rare.
And you are good to go. You successfully created a secondary laser which rotates and destroys all enemy laser and enemy that it touches.