Time for action – adding an enemy ship
To make our enemy ships, we will need a script to turn our enemy ship into a prefab:
The first thing we need to do is create a new script and call it
EnemyShip
. This script will control the movement and shooting of the enemy ships.The script starts off with several variables. The first two define the speed with which the ship moves forward and how fast it turns.
public float moveSpeed = 8f; public float turnSpeed = 0.5f;
The next three variables are for controlling the shooting of the ship. First is the rate at which bullets are fired. It is followed by the range that the ship has to be within to fire at the player. Third is a holder for how long it has been since the last bullet was fired. This will work with the rate of fire to dictate when the ship can fire again.
public float fireRate = 1.5f; public float fireRange = 60f; private float fireTime = 0;
The last two variables will hold a reference to the bullet prefab that will be fired and the point from...