Are You Sure You Know What You’re Doing?

Kristin
3 min readDec 9, 2020

I dedicated today to making sure I understand my code- I don’t want to just follow along and end up with a ton of bugs that I can’t fix- I need to make sure I understand what’s going on. The first thing that I took on what GetComponent- I was so confused on this concept. Why? Because it does so many things. I was under the original thought that GetComponent is called in the exact same way for every time it’s used. Wrong. I learned today (through explanation after explanation) that GetComponent can be used to “make contact” with other scripts, variables in other scripts, components on game objects’ inspectors, and changing values/checkboxes on those inspector items as well. The menu items show up inside the tool tip depending on the order of “menu” options you have to choose from. This basic concept was why I couldn’t understand why my GetComponent calls weren’t the correct syntax many times. I also now understand that return and can be used in two ways (so far that I understand)- 1) inside of a non-void method to ask the program to “return” (pseudo print) a value you want generated, or 2) inside a void method where you simply want the program to “return” to the top of where that particular function was first called. I’m not 100% on this, but I’m 98% sure about that after today.

Daniel also helped me with understanding the concept of time.Time today as well. This was helpful because yesterday I programmed a very memory expensive coroutine that was completely unnecessary to slow the damage my player took (ie. getting hit with two lasers and an enemy all at once, being destroyed in less than a second).

Unnecessary extra memory expense

Instead of using a coroutine, I learned to add a conditional to my if statement parameter instead.

More affordable

After hours, I decided to test what I learned today and use that logical knowledge to clean up how my shields powerup looked- previously, shield strength wasn’t resetting with each new shields powerup collection. I set my powerup lives initially to 4, so that it could withstand 3 hits before the shield turned off- but before, it wasn’t resetting with a new powerup. To do this, I “double checked” the powerup color and lives by explicitly calling the shield strength and color in the initial activation script of the powerup.

Fresh new paint
Shields powerup and damage behavior are more reasonable

Also, equipped with fresh concepts and logic, I was able to finally fix my thruster code.

My thruster scaling bar finally moves according to player damage

Positive Affirmation: Although I may not always understand something in the moment, I can still gain understanding eventually. C# and Unity come effortlessly and easily to me. I understand C# and Unity so well that I can teach and debug this code extraordinarily well. I love coding C# in Unity. Coding brings me tranquility and peace.

My positive affirmation worked yesterday, so maybe it will work again.

Stay well friends,

Kristin

--

--

Kristin

Astrologer turned Software Developer who is aiming for the stars to land on the moon. Kristin the Developer is the Celestial Sleuth.