Space Invaders


Itch.io link – https://challenger2.itch.io/space-invaders

Starting with a green square as the player and a red square for enemies, i placed them in the environment and added a script to the player to allow movement.

The player can only move horizontally across the screen and by pressing space may fire the gun, the gun fire rate is limited by the variable (nextFire).

The player speed is limited by a speed variable that changes the player speed by increasing or decreasing the number contained within.

Player Script

The bullet is created from a prefab sprite, attatched to this sprite is the bullet behaviour script, within this script is the code defining the bullet speed which can be altered if nessiscary by changing the ‘speed’ variable, if the bulllet goes above y = 6 it is destroyed by the game as to not impact performance. Upon collision with the enemy sprite the bullet is destroyed along with the enemy sprite, this is caused triggered by the bullet impacting the enemy sprites hitbox. the instantiate command then respawns a new enemy at a random position.

bullet script

The Enemy script contains the enemies movement allowing the downward movement of the enemy once again the speed can be changed by altering the variable.


Leave a Reply

Your email address will not be published. Required fields are marked *