Guide created by Jonathan Weinberger

Like I mentioned in my last blog, I will be spending an adequate amount of time familiarizing myself with Unity C# coding. Today’s focus was on If-Then-Logic. To explain in it’s simplest terms - ‘IF this happens THEN this is the outcome’. However. I was not able to fully complete the course and will only be discussing IF statements.

To begin, I would like to note that //_____(reference green-colored lines 9 & 15) are called pseudo-codes or comments to help you ‘title’ the code sequence.

A variable must be declared inside of a class i.e. Public Class Player: MonoBehaviour (reference line 5). Variables are the only things that can be declared outside of methods (void Start / void Update). Variables can also be used inside of void Start and void Update (reference line 10 & 16) and must be inserted in between the brackets {_these are known as local variables_}.

If () /else statements (aka variables) run inside methods. It’s in this space that we can assign value to a variable. To give value to a variable, I would first create Public/Private int_X; (X = value). In the code example above, X =pointSystem as the value (reference line 7). Then I went on to place the ‘action’ if () statement in void Update to assign a key in Unity (reference line 18). Assigning a key i.e. SPACE, UP, DOWN, is placed in void Update since the state gets reset with each frame. There are 3 ways to do so:

  • Input.GetKey: when you are holding down the button
  • Input.GetKeyDown: when you press the button down
  • Input.GetKeyUp: when you let the button go.

Next I created a Debug.Log, which allows the console (via Unity) to print out the script within the code. This will inform you that if () / else statements were activated.

To complete the code, I then assigned a ‘outcome’ to the ‘action’. It can be done using the codes(reference lines18–22):

  • __X = __X + # (This is read as _value=_current value + the amount you want the value to be)
  • __X += #(the amount you want the value to be)

So to tie everything together following the code above, if I (the player) hit SPACE, the pointSystem value becomes 10.

Modern-day Woes: Island Edition. Living in Hawaii, especially on the island of Lana’i, you learn to appreciate big-city connectivity and access to “higher faster internet speeds” — every internet/cable service provider on this planet. On Lana’i, it’s a different story. You have days where internet service of no more than 200 mbps, work perfectly. Then, you have days where the smallest breeze or light rain shower affect connectivity and you’re kicked back to B.C. (before computers) :) If you live in a multi-generational home, which most folks do on Lana’i…well good luck, may the internet be in your favor. Today was one of those B.C. days. I was able to get some work done in the AM, but before lunch even came, I was kicked off the network. I was not able to connect to the internet until this afternoon. Thus the reason behind such a short blog ;)

Gaming Developer Intern