The Unity Space Shooter Tutorial is one of my favourite Unity tutorials. The game itself reminds me of the classic Asteroids arcade game. You will gather a lot of knowledge and experience with Unity interfaces and C# coding through the creation of this game.
The assets in this game (Asteroids, Space Ships, etc.) are provided for free through the Unity Asset Store. You can use these assets in any game you create, even if your game is commercially based.
Introduction To The Unity Space Shooter Tutorial
The game setup consists of transferring the spaceship to the playing area. This is itself is not enough as the camera has to be positioned in such a way that the game is in the correct view.
Camera, Lights, Action.
In this section of the tutorial, you will set up the project in a specific way, in other words, the location of the project files, the importing of assets, etc. The layout is also modified and saved. I like the layout, in particular for this type of game.
Now we setup the player GameObject which is the spaceship that is also called the player. This portion is incredibly easy as its drag and drop. The camera, lighting and background are created and placed in very precise coordinates. The lights, in particular, need to be pointing in a specific direction so that it lights up the ship in a very specific way when it moved. You will use several lights to highlight the ship so that it looks good in the game.
The next three lessons revolve around moving the player, creating the laser shots and then shooting these laser bolts. This portion of the lessons does use scripting quite a lot, and for my game, this is code that I can use.
The creation of a border is quite an attractive solution to a few of the issues that are created by the hazards and laser bolts. Each asteroid and laser bolt create an instance of the item in the actual game, this mean is you play the game long enough there will be thousands of asteroids and bolts still in game memory. The boundary helps solve this problem as you can create a script that will destroy both the asteroids and the bolts if they hit the game boundary.
Creating Hazards with Explosions
One of the main parts of the game is the creation of the dangers and how they move randomly from the top of the screen towards your ship. The coding for this is interesting as it will touch on a few concepts that will be useful in other games that you will create.
At this stage of the game, you will have a player ship, the ship weapon and the asteroids that are trying to destroy your ship. You now have to coordinate all the above in a game controller script. The script will end up doing quite a few things such as the display of the score, calculating the score, spawning waves of asteroids and ending the game at the appropriate time.
The game would be quite boring at this stage as there is just one wave of hazards. The solution to this is creating a while loop that will continuously send the asteroids from the top of the screen. This adds longevity to the game as in theory the game will never end if the play is good enough to keep on destroying and dodging the hazards.
The audio for the game is also supplied through the Unity Asset store. Adding the sound to explosions, shooting and the background music is relatively simple however it adds depth to the game.
Points and Score
Adding points to the game provide that little extra push for the player to beat their previous score. Points will help a lot with game retention. If you create point you obviously need to display the score, so you will be shown how to code both of these aspects of the Space Shooter Game by making use of the GUIText component.
Ending and Building the Game
In this section, you will learn how to code the ending of the game by breaking out of the while loop when the player ship is destroyed. The game is also built for web deployment. The web deployment will allow you to play the game through most internet browsers.