Time for action – flying asteroids
The first objects we will be avoiding in our infinite space will be asteroids:
To make the asteroids work, we will first need to make the player ship's rotation and speed available for the asteroids to use. To do this, we need to create a new script and call it
PlayerShip
.Again, this script starts with a group of variables. The first is the speed of the player's ship. The asteroids and other objects in the space will use it to move around the player. The second variable will hold a reference to the
TiltSteering
script that we created earlier. This will give us access to the ship's rotational speed. The last variable is a static variable that will hold a reference to the instance of this script that exists in the scene. This will allow other scripts to access the information stored by this script. We call theuse
variable to indicate to other scripts that this is the instance they should access.public float speed = 10f; public TiltSteering tilt; private...