Day 3: Vanishing Act

Brittany Lumanlan Martin
2 min readNov 26, 2020

It’s the end of Day 3 of my internship, and C# is becoming less of a mystery to me! Today I’ll dive into some concepts I learned, including a hurdle that tripped me up for about an hour today.

I began my day by going over the tail end of the “Shooting” section I had planned to finish last night, which involved cleaning up the code in my scripts in preparation for the “Enemies” section. Next, as you may have guessed, I dropped in an enemy for the player, the cube. Fleshing out the script for the enemy was similar to the process for the player. First, I right-clicked into the “Hierarchy” and selected 3D Object -> Cube. In the “Materials” folder, I created a new material named “Enemy_mat” and used the Albedo function to make it red. Next, I created a Prefab for the enemy, a function in which you can configure different components and property values for an object. To round off these initial steps, I created and attached a script to the enemy cube entitled “Enemy” to work on in Visual Studio (a development program by Microsoft used to create programs, apps, and more).

Further into the “Enemies” section, I was introduced to the idea of game physics — specifically, the process of creating a reaction when two objects collide in a game. In this case, as I am building a space shooter, a “physical” reaction happens when a laser hits the enemy, or when the enemy crashes into the player. This involved applying a component to the enemy and the laser called “Rigid Body”. Otherwise, objects tend to pass through each other during gameplay.

Towards the end of this section, in a module called “Player Lives And Damaging Reboot”, I hit a snag in which every time I ran the gameplay, my enemy would vanish before I could even move to destroy it! If I stopped the game and restarted, it would appear again, which became maddening very quickly. Finally, after searching through several Unity forums, I came across the solution: Unity had been reading my enemy script to immediately destroy the enemy object upon loading the game. A huge thank you to the stranger in a forum who had the same problem last year, then solved it. See the screencap of my script and solution below:

The missing piece! By inserting the line of code highlighted by the red arrow, the enemy character would not immediately destroy itself the moment the game loaded. Previously, I had only written in the line below it, which caused the enemy to immediately vanish when first loading the game.

Although we have a 4-day weekend coming up at GameDevHQ, I’ll be pushing through and completing more sections — which, of course, means new progress blogs all weekend. Until then!

--

--