Objective: Learn how to write efficient, clean, and readable statements.

Switch statements have the same concept as a bunch of if/else statements. You use the keyword ‘switch’. You switch through a variable, which is the powerupID variable. You have a case for every outcome you’re checking. Inside switch(powerupID), you insert the cases. For case 0: player.TripleShotActive(); for case 1: Debug.Log(“Collected Speed Boost”); for case 2: Debug.Log(“Shields Collected”); You end each code statement with the ‘break’ keyword. If neither case 0,1, or 2 were an option you would use the ‘default’ keyword.

--

--

Objective: Learn how to use if/else statements.

Go to the Speed folder in the Filebase asset package and drag the Powerup1_0008_00000 sprite into the Hierarchy and change the name of it to Speed_Powerup. Add the BoxCollider2D, Powerup and RigidBody2D components just as you did for the Triple Shot Powerup. But, the Powerup component script must be modified to include behavior that’s specific to the Speed Powerup. You must create a powerupID to differentiate between the types of powerups. The powerupID field will be an int. If it’s a 0, the powerup is a Triple Shot, if it’s a 1 the powerup is a Speed, and if it’s a 2 the powerup is a Shield.

The logic for this is pretty simple. Inside the OnTriggerEnter2D method, use if/else statements to distinguish between the powerup IDs.

--

--

Objective: Learn when and how long powerups should spawn.

We’re going to modify the Spawn Manager to include the TripleShotPowerup and spawn them just like the enemies are spawned. We want to spawn a powerup every three to seven seconds. In the SpawnManager script, insert the word ‘Enemy’ in the IEnumerator SpawnRoutine() so that it says IEnumerator SpawnEnemyRoutine() and create another IEnumerator called ‘IEnumerator SpawnPowerupRoutine()’. You have to reference the TripleShot GameObject Prefab. You don’t need a container object like the container for the Enemy object because the TripleShot will not be reused and will be destroyed instantly.

--

--

Objective: Add triple shot power-ups to the game.

Drag the Laser from the Prefabs folder into the scene and duplicate it twice. Position the Laser duplicates so that three lasers shoot from the Player game object. Make sure the Y values are the same on the wings.

Create an empty GameObject and name it ‘Triple_Shot’ and parent the three Lasers to it. Make it a Prefab so that it can be instantiated later. Now, delete it from the scene.

To activate the Triple Shot, initialize a bool in the Player script: private bool _isTripleShotActive = false and in the FireLaser() method if _isTripleShotActive == true, fire Triple Shot if not, fire one shot. But first you need to reference the Triple Shot GameObject.

--

--

Objective: Overview of how Sprites work.

We’re going to be transitioning from prototyping to production. The art assets that we downloaded from Filebase will be used. 3D objects can have materials attached to them and 2D objects are called Sprites. In Unity, in the Scene tab at the top, click on 2D. Now you’re in a perspective view and you can view the Player as a flat surface but the Player is still 3D. Search through the Assets folder for the SpaceBG_Overlay Sprite and drag it into the Hierarchy. Change the name of it to ‘Background’ and scale it up to fit the length of the screen.

--

--

Objective: Learn how to incorporate Unity assets into the game.

We’re done with prototyping, now we can polish the game with hi-fidelity graphics and include power-ups, animations and explosions. To do this, go to Filebase: https://filebase.gamedevhq.com/ and search for ‘2D Galaxy Assets’ under Projects -> Tutorials. Download the file, click on it and import the Audio and Sprites folder into your Unity project.

--

--

Objective: Stop game objects from spawning all over the place in the Hierarchy.

There are a lot of Enemy game objects spawning in the Hierarchy which is messy and can be hectic when testing the game. To stop this, you should make a child container object of the Spawn Manager. In the Hierarchy, create an empty GameObject and make it a child of the Spawn Manager and name it ‘Enemy Container’. All of the Enemy objects will be placed in the Enemy Container. In the Spawn Manager script, reference the Enemy Container by typing [SerializeField] private GameObject _enemyContainer; Save the script and drag the Enemy Container game object into the slot.

In the Coroutine method, create a GameObject variable to store the spawned game objects. Get the parent of its transform and assign it to the enemy container transform.

--

--

KW Development LLC

KW Development LLC

Seasoned, result-oriented, highly professional individual with a stellar record of expertise in back-end development and game development.