For this program, I have included two scripts for the player character. The first of these is called “scr_PlayerMovement”.

I start off by declaring my variables. “moveSpeed” controls the movement speed of the player, “rb” stores the rigidbody of the player sprite and “camera” stores the camera. Vector2 movement stores a reference to the players movement and vector2 mousePos stores the mouse position as a variable.
in void Update I have stored the values for the player input and use these as the x and y values. I have also set vector2 to the mouse position so that the game can track the location of the mouse cursor. In void FixedUpdate I control the movement and look direction of the player.

I start off by declaring my variables. These are bulletSpawnLocation which handles the location in which the bullet is created, bulletPrefab which acts as a reference to the prefab for the bullet and bulletForce which controls the strength of the bullet.
In void update I control the player’s input. If the button “Fire1” is pressed, the function in void Shoot() will be ran. in void Shoot I control the player shooting the bullet. A bullet is created from the prefab and spawned into the bullet spawn location. The bullet then moves forward with force.

The image above displays the code for the enemy movement. I start off by declaring my variables. These are “moveSpeed” which controls the speed at which the enemy moves, “rb” which is a reference to the enemy’s rigid body, “player” which is a reference to the player character and “playerRb” which is a reference to the player’s rigidbody.
In void start I find the player object and then find the player’s rigidbody2D. In void FixedUpdate I make it so that the enemy always faces the player and moves towards them.

The image above displays my script for the bullet behaviour. I start off by declaring my variables. These are bulletTransform which stores the movement of the bullet and enemyRespawnPrefab which stores the prefab for the enemies that respawn when killed.
In void On CollisionEnter2D, I control what happens when the bullet hits the enemy. The enemy is destroyed and then a new enemy is respawned in a random location. After this the bullet is destroyed.
While this code is functional, there are many improvements I could make. First of all I haven’t added any objects that could be used as cover to hide from enemies. I also would like to make it so that the enemies can shoot. Another good addition would be audio which would make the game much more appealing to the player.