Objective: Reload the scene by pressing the “R” key on game over.
Like with the gameover text, we want a message that will pop up on gameover. We don’t want it to flicker though, so basically doing the same thing that we did here minus the flickering part will do the job just fine.
But now we want to be able to restart the whole scene by pressing “R”. To do this, we’ll need to create another empty object named GameManager, and a script for it with the same name.
Before we dive into the scripts, go to file >…
Objective: Create a game over screen that flickers when the player has run out of lives.
In the canvas object, make another Text child object and name it GameOver_Text, and change the actual text to how you want it. By default, this text shouldn’t be active, so you can make the box next to the name unmarked. Now go to the UIManager script and attach the object to a Text variable.
What are loops?
They’re a set of instructions in code that get repeated over and over again as long as certain circumstances are in place or it’s broken.
There are four types of loops when it comes to coding in C#.
Do While Loops
For now, let’s focus on the For Loop.
A for loop will follow a set of instructions and repeat itself until it finishes. This works great for counting values whether it’s a timer or dealing damage to a group of enemies at once.
This is an example of how a…
Objective: Create a visual system with the UI Manager that shows how many lives the player has left before game over.
Like the score system, this will be taking place within our canvas object. This time, however, we’ll be using an image instead of text. So right click on canvas, go to UI, then click image.
Objective: Implement a system that adds a UI element where a number increase by 10 every time an enemy gets destroyed by a laser.
Start with right clicking within the Hierarchy in Unity. Go down to UI, then click “Text”. The basic one will do just fine. This should create two objects, one called “Canvas” and another called “Event System”, then there should also be a child object in the canvas that you can rename to “Score_Text”.
With the score_text object selected, you can change the text itself, change the size and color, and change the alignment and anchor points…
GetComponent is a very intensive process that can overwhelm our game if we’re not careful with how often we use it. A part of keeping our code clean and efficient, is finding ways to use GetComponent as little as possible.
Changing where we use this command can make all the difference.
For instance, in the 2D shooter game I’ve been making, so far whenever I use GetComponent, I’ve been writing the code for it within the methods I need it. …
Objective: Add a visual element that will appear once the shield has been activated, disappear after a hit, and give it an animation.
Once we get the behavior of our shield working, we want to drag the sprite for the part that will be going around the space ship into the hierarchy. More specifically, you’ll want to drag it onto the player, so it becomes a child object.
Objective: Add the shield powerup to the spawn manager and script behavior so player doesn’t take damage while it’s active.
Adding the powerup to the spawn manager is quite simple once we add the power of arrays to our script. I’ll go into arrays in another article, but for now we want to change the tripleshotpowerup variable in the spawn manager script to just “powerUps”. We also need to add brackets to the variable type.
Adding the animations for the Speed Boost and Shield will be just like what we did for the Triple Shot. Make sure that both prefabs are easily selectable by dragging them to the hierarchy and then click the one you want to start with. While it’s selected, go to the animation window and click “create”
Creating the prefab for our shield powerup is pretty going to be just like adding the first two. Drag the sprite you want into the hierarchy to create a Gameobject, rename it “Shield_Powerup”, and start adding components.
First, add the Circle Collider and make sure “is trigger” is checked.