Day 9 | It’s Starting to Click + a Must-Watch Series

July 15, 2022

I’m focusing more on scripting today so that I can script more of Flappy Birds on my own. I want to be able to script it myself. I found a video that’s a really good one called “Learn C# Scripting for Unity in 15 Minutes (2022 Working).” This is part 1 of a 3 part series. And I would HIGHLY suggest watching it: https://youtu.be/9tMvzrqBUP8

For some reason all of this is just starting to click with me now. I think I’m just starting to know enough that I’m able to understand these tutorials better—I’m able to soak them in more. It’s a great feeling. It appears that there’s really a few Functions that I really need to get the hang of at the start to be able to manipulate things and be able to think through things on my own:

    1. GetComponent<>() — within the ”<>” you’re supposed to put the component you want to access.

    2. Input.GetKeyDown(KeyCode.add whatever key you want to be affected here)

    3. OnMouseDown()

This is a good start because it allows me access to the Components that are attached to the GameObject the script is attached to, but it also allows me to manipulate those Components too.

I have some experience using the programming language C, and one thing that I’m realizing that’s different with C# scripting in Unity from actually coding barebones is that the Unity script is attached to the GameObject by a simple drag and drop within Unity itself. Then, once you do that, you’re able to call the GameObject within the script simply by writing gameObject. It doesn’t have a special name or anything, and you don’t have to write a variable for it. In all of your scripts for various different GameObjects, they all have the same name and can have the same name because they are independent of each other. The scripts are separate. I’m sure this is obvious to many, but for me this is a really big insight that I learned and is helping me have breakthroughs.

The video I linked to earlier is talking about how to write the script for loading other scenes within your game. That’s going to be a good thing to know for me for my game. Before you can access other levels that you might create, you need to put “using UnityEngine.SceneManagement;” at the top of the script in order to access all scene management-related functions.

Questions for later

One thing I’m struggling to understand is why some Functions have a “void” in front of them and others don’t. I understand the concept that this is saying that nothing is returned into the program once the function has ran, but why don’t all functions signify whether they are returning nothing or something? Some functions have no signifier at the front. Why?

Also, I’m not understanding the concept of public and private Functions and variables. For instance, at 11:25 of the video linked above:

In his example, why does the variable “Rigidbody rb;” not have a “public” or “private” in from of it but “GameObject winText;” does? Is it because “Rigidbody rb;” is a variable already associated with the current GameObject attached to the script that is going to hold some information within that script, whereas “public GameObject winText;” is calling another GameObject, outside of the current GameObject’s script, into existence so that it can be manipulated based on what the current attached GameObject does? That was complicated to write, and who know if I’m on to something. I’ll look it up later.

Previous
Previous

Day 10 | What Is a Class in C#?

Next
Next

Day 8 | It all starts with a GameObject