ASTEROIDS - BEHAVIOR
In this section, I will show you how I added moving behavior to the asteroids. Also, once the asteroids move away from the scene, it should be destroyed to save the memory of the game.
BEHAVIOR: MOVE TOWARDS SPACESHIP
This behavior can simply be obtained by adding MoveObjects.cs script that we used to move the laser bullets forward. Vector3.forward used in the script makes the object move forward, z-direction. So in the scene, the orientation of the asteroids was checked. The local forward direction of each asteroids were made such that it pointed towards the spaceship.
DESTROY SPACESHIP OFFSCREEN
To Destroy asteroids once it gets offBounds, a new variable "lowerBounds" was declared in the script DestroyOffScreen.cs Script. The script was then attached to each asteroids.
The script now check if the objects are out of Bounds (upperBound for laser bullets and lowerBound for asteroids) and destroys the gameObjects that it is attached to.