Day 46: New Enemy Part 3

Objective: Add the new enemies weapon.

Now that everything for movement has been figured out, its time for the weapon.

To start we will need a ScatterBomb prefab. Like our laser we created earlier, we’ll need a box collider2d, rigidbody2D and the script for it. For the sprite we are using the laser sprite as a place holder till I find something else. For boxcollider2D, make sure is trigger is checked and rigidbody2D, gravity is set to zero.

Now for the script. Right now all that is being done is moving the laser up, reference to the local rotation of the object. We also check to see if the position is off the screen and if so destroy the object.

We’ll need to add a OnTriggerEnter2D function as well. This will allow the scatterbomb to damage the player.

That’s all we have for the scatterbomb. Next will be the calling the scatterbomb prefab and spawn them in a circle and go outwards.

In the enemy script we’ll check to see which enemyID has been spawned and if it is related to the zigzag enemy fire this instead of the regular laser.

We will put the instantiate in side a for loop, this for loop is get an angle from zero all the way to 360. Wen the object gets instantiated it’ll be put into a variable. That variables transform will use eulerAngles to multiply the Vector3.forward by the angle. This will rotate each object by 30 degrees. It’s what gives us the circle of lasers.

And that’s all it took to create this weapon.

I am passonate on learning to program and use Unity to become a skillful Unity Developer