Lesson 10 – Vector Maths

I write this to you with no idea how to deliver this information. All I know is that I must deliver this information. Something tells me I must. Many of it will be a re-iteration of already explained information. But…what isn’t? This is more for me then it is for you, potential reader. This is for me to tell myself “You’re doing good, kid”. I WILL NEVER STOP UNTIL I MAKE THE LIKES OF MIYAMOTO PROUD!!!!

By now you may have noticed a lot of talk in the Unity docs regarding Vectors. But what are they exactly? Is it an objects position? Does it have anything to do with images? HELP!

What is a Vector?

– Put simply: a Vector is a line drawn between two points. Not exactly the answer you were expecting, huh? Well, tough! A lot of your answers won’t be filled with magic and rainbows!
– You can’t speak about Vectors without mentioning magnitude: the length of a Vector.

That was cute…but seriously, what is a Vector?

I’m not pulling your chain. On the very base, this is what a Vector and magnitude are. Luckily for you, in relation to what you need to know for Game Development and Unity, it gets more complex:

2D-Vectors

– A 2D-Vector is a way of representing a point from the Origin point (0,0) to any point on the 2D plane. Also note: Since it is relative to the Origin point, it has an implied direction.

2DVector

Continue reading “Lesson 10 – Vector Maths”

Advertisements

Lesson 9 – Update () and FixedUpdate()

Today we discuss another set of very common Methods() derived from Unity’s Monobehavior class. As mentioned before, MonoBehaviour is the base class from which every Unity script derives. AKA: the class that holds all of the Unity scripts we work with.

The methods in question are Update() and FixedUpdate(), and if you’ve been paying any attention at all you will have seen them being put to use in a script or two by now.

What is Update() and FixedUpdate()?

Continue reading “Lesson 9 – Update () and FixedUpdate()”

Lesson 8 – Awake() & Start()

You may have noticed that there is a common element living in the beginning of most of our C# scripts within Unity. Mostly you may have noticed the Start() Method living close to the beginning of your class script. This rhythm is by design, and it is one of many built-in Unity Methods provided to us by the Monobehavior class.

So, what do they do?

I want you to think of Start() and Awake() as the beginning to a good book. You can not have a middle or end without the beginning laying down a solid foundation of characters/settings to work with. The same can be said about the Start() and Awake() methods.

Continue reading “Lesson 8 – Awake() & Start()”

Lesson 7: Scope and Access Modifiers

From this lesson moving forward, we’re going to be speaking of C# scripting in a way that more relates to its functions within Unity. Scope and Access Modifiers is a fantastic place to begin.

Before we begin, let’s set our state of mind to the following:
When you are writing scripts for your game, whether it be behavior scripts for character movement, physics, or shooting a gun, we can safely say that it will be necessary for these systems to interact.

What is a Scope?

The scope of a variable is the area in the code in which the variable can be used in. A variable is local to the place in code that it can be used. Code blocks are generally the area that defines where the code can be used, and they are denoted by braces/brackets {}.

Examples of Scope:

Continue reading “Lesson 7: Scope and Access Modifiers”

Lesson 6: Loops

Like Variables, Functions, and Conditional statements mentioned in our previous lesson, it’s best to get familiar with programming Loops — boy-oh-boy will you need loops in your game developing future.

What are Loop statements?
Simply put, Loop statements are ways for you to execute a block of code {} multiple times. If you need something repeated a specific number of times — or an infinite amount of times, it can be written in the code by you!

Why would I use Loops in Game Development?

Please allow me to speak very loosely here. You would use Loops in Game Development if you wanted to repeat an action/behavior multiple times. Maybe you want the animation of a cloud persistently moving left through the x-axis, in which case you create an infinite loop to make it so. Or maybe you want to loop the act of a machine gun shooting until it runs out of ammo, in which case you loop the action until a condition is met (ammo == 0).

Please Note: In my experience, once a condition is met within a loop, the block of code no longer get’s repeated, and the loop is terminated.

Continue reading “Lesson 6: Loops”