From Photographer to Video Game Creator — Day 7
Let’s dive right in! Today, I was kicking off a new section dealing with the User Interface (UI), and this has been BY FAR the most challenging day yet.
To start things off, every item for the UI was created under a new game object that I called the Canvas. This keep everything organized and in one location. The first task was to create a method for depicting the Players current lives on the screen. I created an array on my UI Manager script that would show different images allowing the player to see how many lives they have remaining. These images are also known as Sprites.

Next up was to create a score system. This one really threw me for a loop. I needed the Enemy script to communicate with the Player script every time a laser destroyed an enemy. Here is my first attempt at the script communication:

At this point, everything is fine and it all works out. BUT, the issue comes with the “GetComponent” command. This is a very expensive piece of code, meaning that it takes a ton of processing power every time it is ran. So if I am destroying a lot of enemies very quickly, this code has to run each time an Enemy is destroyed. An easy was to optimize this is by moving the “GetComponent” of the Player into the void Start. Now the command is only ran once and the information is ready to go on the Enemy script.

Now that this connection has been made, I can shorten up my code by adding an “if statement”. This does take more lines of code, but the cost when it comes to processing power is WAY less, making the game run faster.

At this point, I have a very basic, but functioning UI that shows player lives and current score!

The next step was to show the player that the game was over when they ran out of lives. I added some text boxes that would show “GAME OVER” and even an option to press the ‘R’ key to restart the game. The final touches came by creating a flicker routine as an IE Numerator that would begin when the player died.

I know it looks bland at this point, BUT everything pops up when it’s supposed to AND the “GAME OVER” text flickers in and out AND the player can now press ‘R’ to restart!

Now it was time to add a main menu. This meant creating a new Main Menu scene that was separate from the Game scene that I’ve been working in up to this point.

By creating the Main Menu scene, I was able to add images, text blocks, and a button that would allow the player to start a new game!

That was a lot for today and I ran into quite a few issues. Script communication is extremely tricky and when an object isn’t recognizing another object it can be super difficult to figure out where the problem is. I now have 8 scripts running in this project so I’m trying my best to remember which commands are coming from which scripts!
Looking forward to tomorrow where I start adding some more visual effects to my game!
-Myles M.