Let’s Add Some New Enemy Types to our 2D Galaxy Shooter in Unity!
Objective: To create 2 new enemy types that are going to have different movement, weapons and avoidance features.
Firstly I have gone ahead and grabbed some 3D spaceship game objects to take a top down photo of to edit and save as a PNG file in Photoshop, exporting them out onto a sprite sheet. I now have 3 new models for 3 different types of enemies. The first enemies features that I have previously created will remain as is, but these 2 new ones are going to have some pretty cool features!
Enemy 1-Original
Enemy 2-Teleport
This enemy is going to have new angular movement with a different spawn and end position every time. It will also have a random chance to spawn with a shield that is going to take 2 hits from the player’s lasers. Finally, it will have an avoid shot feature that uses raycasting to detect a player’s laser in front of it and it will teleport to another part of the screen randomly. This will have a cooldown so that the player has a chance to destroy it!
Enemy 3-Laser
This enemy is also going to contain a new movement which is going to be sideways across the screen. If it reaches the bounds of the screen it will automatically appear on the opposite side. It will also have a random boost feature that will be used on a random timer. Finally it is going to shoot a nasty laser beam like the player!
Components List
For all 3 of our enemies we are going to need the following components:
- Sprite Renderer — with Sorting Layer set to ‘Foreground’ and Order in Layer is ‘1’.
- Box Collider 2D — with Is Trigger ‘ticked’. Box Collider set up appropriately around the sprite image.
- Rigidbody 2D — Body Type set to ‘Kinematic’, Collision Detection set to ‘Continous’ and the Sleeping Mode to ‘Start Awake’.
- Animator — Which contains the explosion animation.
- AudioSource — Which contains the ‘Explosion Sound’ in the AudioClip box.
- Enemy Scripts— Which is going to run the different movements, weapons and features.